renoki-co/php-k8s

View on GitHub

Showing 194 of 198 total issues

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

namespace RenokiCo\PhpK8s\Traits\Resource;

use RenokiCo\PhpK8s\Instances\Rule;
Severity: Major
Found in src/Traits/Resource/HasRules.php and 1 other location - About 4 hrs to fix
src/Traits/Resource/HasSubjects.php on lines 1..75

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 179.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

Similar blocks of code found in 2 locations. Consider refactoring.
Open

<?php

namespace RenokiCo\PhpK8s\Traits\Resource;

use RenokiCo\PhpK8s\Instances\Subject;
Severity: Major
Found in src/Traits/Resource/HasSubjects.php and 1 other location - About 4 hrs to fix
src/Traits/Resource/HasRules.php on lines 1..75

Duplicated Code

Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

Tuning

This issue has a mass of 179.

We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

Refactorings

Further Reading

The class K8sPod has an overall complexity of 57 which is very high. The configured complexity threshold is 50.
Open

class K8sPod extends K8sResource implements
    Attachable,
    Dnsable,
    Executable,
    InteractsWithK8sCluster,
Severity: Minor
Found in src/Kinds/K8sPod.php by phpmd

The class Container has an overall complexity of 50 which is very high. The configured complexity threshold is 50.
Open

class Container extends Instance
{
    /**
     * Set the image for the container.
     *
Severity: Minor
Found in src/Instances/Container.php by phpmd

The class Container has 15 public methods. Consider refactoring Container to keep number of public methods under 10.
Open

class Container extends Instance
{
    /**
     * Set the image for the container.
     *
Severity: Minor
Found in src/Instances/Container.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

The class K8sResource has 13 public methods. Consider refactoring K8sResource to keep number of public methods under 10.
Open

class K8sResource implements Arrayable, Jsonable
{
    use HasAnnotations;
    use HasAttributes;
    use HasEvents;
Severity: Minor
Found in src/Kinds/K8sResource.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

Method loadKubeConfigFromArray has 78 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected function loadKubeConfigFromArray(array $kubeconfig, string $context = null)
    {
        /** @var \RenokiCo\PhpK8s\KubernetesCluster $this */

        // Compute the context from the method, or in case it is passed as null
Severity: Major
Found in src/Traits/Cluster/LoadsFromKubeConfig.php - About 3 hrs to fix

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        public function addNodeSelectorPreference(array $expressions, array $fieldsExpressions, int $weight = 1)
        {
            foreach ($expressions as &$expression) {
                if ($expression instanceof Expression) {
                    $expression = $expression->toArray();
    Severity: Major
    Found in src/Instances/Affinity.php and 1 other location - About 2 hrs to fix
    src/Instances/Affinity.php on lines 15..41

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 122.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Similar blocks of code found in 2 locations. Consider refactoring.
    Open

        public function addPreference(array $expressions, array $fieldsExpressions, int $weight = 1)
        {
            foreach ($expressions as &$expression) {
                if ($expression instanceof Expression) {
                    $expression = $expression->toArray();
    Severity: Major
    Found in src/Instances/Affinity.php and 1 other location - About 2 hrs to fix
    src/Instances/Affinity.php on lines 51..77

    Duplicated Code

    Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

    Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

    When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

    Tuning

    This issue has a mass of 122.

    We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

    The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

    If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

    See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

    Refactorings

    Further Reading

    Function loadKubeConfigFromArray has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
    Open

        protected function loadKubeConfigFromArray(array $kubeconfig, string $context = null)
        {
            /** @var \RenokiCo\PhpK8s\KubernetesCluster $this */
    
            // Compute the context from the method, or in case it is passed as null
    Severity: Minor
    Found in src/Traits/Cluster/LoadsFromKubeConfig.php - About 1 hr to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method makeWsRequest has 38 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function makeWsRequest(string $path, Closure $callback = null, array $query = ['pretty' => 1])
        {
            $url = $this->getCallableUrl($path, $query);
    
            // Replace the HTTP protocol prefixes with WS protocols.
    Severity: Minor
    Found in src/Traits/Cluster/MakesWebsocketCalls.php - About 1 hr to fix

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      <?php
      
      namespace RenokiCo\PhpK8s\Traits\Resource;
      
      trait HasLabels
      Severity: Major
      Found in src/Traits/Resource/HasLabels.php and 1 other location - About 1 hr to fix
      src/Traits/Resource/HasAnnotations.php on lines 1..52

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 110.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Similar blocks of code found in 2 locations. Consider refactoring.
      Open

      <?php
      
      namespace RenokiCo\PhpK8s\Traits\Resource;
      
      trait HasAnnotations
      Severity: Major
      Found in src/Traits/Resource/HasAnnotations.php and 1 other location - About 1 hr to fix
      src/Traits/Resource/HasLabels.php on lines 1..52

      Duplicated Code

      Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

      Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

      When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

      Tuning

      This issue has a mass of 110.

      We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

      The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

      If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

      See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

      Refactorings

      Further Reading

      Avoid using short method names like Expression::in(). The configured minimum method name length is 3.
      Open

          public function in(string $name, array $values)
          {
              return $this->setAttribute('key', $name)
                  ->setAttribute('operator', 'In')
                  ->setAttribute('values', $values);
      Severity: Minor
      Found in src/Instances/Expression.php by phpmd

      ShortMethodName

      Since: 0.2

      Detects when very short method names are used.

      Example

      class ShortMethod {
          public function a( $index ) { // Violation
          }
      }

      Source https://phpmd.org/rules/naming.html#shortmethodname

      Avoid using short method names like HasAttributes::is(). The configured minimum method name length is 3.
      Open

          public function is(self $instance)
          {
              return $instance->toJson() === $this->toJson();
          }
      Severity: Minor
      Found in src/Traits/Resource/HasAttributes.php by phpmd

      ShortMethodName

      Since: 0.2

      Detects when very short method names are used.

      Example

      class ShortMethod {
          public function a( $index ) { // Violation
          }
      }

      Source https://phpmd.org/rules/naming.html#shortmethodname

      Method getWsClient has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getWsClient(string $url): array
          {
              $options = [
                  'timeout' => 20,
                  'tls' => [],
      Severity: Minor
      Found in src/Traits/Cluster/MakesWebsocketCalls.php - About 1 hr to fix

        Avoid using undefined variables such as '::$stdChannels' which will lead to PHP notices.
        Open

                            $channel = static::$stdChannels[substr($data, 0, 1)];

        UndefinedVariable

        Since: 2.8.0

        Detects when a variable is used that has not been defined before.

        Example

        class Foo
        {
            private function bar()
            {
                // $message is undefined
                echo $message;
            }
        }

        Source https://phpmd.org/rules/cleancode.html#undefinedvariable

        Method buildStreamContextOptions has 27 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            protected function buildStreamContextOptions(): array
            {
                $sslOptions = $headers = [];
        
                if (is_bool($this->verify)) {
        Severity: Minor
        Found in src/Traits/Cluster/MakesWebsocketCalls.php - About 1 hr to fix

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              public function watch(Closure $callback, array $query = ['pretty' => 1])
              {
                  if (! $this instanceof Watchable) {
                      throw new KubernetesWatchException(
                          'The resource '.get_class($this).' does not support watch actions.'
          Severity: Minor
          Found in src/Traits/RunsClusterOperations.php and 1 other location - About 55 mins to fix
          src/Traits/RunsClusterOperations.php on lines 306..322

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 99.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Similar blocks of code found in 2 locations. Consider refactoring.
          Open

              public function watchAll(Closure $callback, array $query = ['pretty' => 1])
              {
                  if (! $this instanceof Watchable) {
                      throw new KubernetesWatchException(
                          'The resource '.get_class($this).' does not support watch actions.'
          Severity: Minor
          Found in src/Traits/RunsClusterOperations.php and 1 other location - About 55 mins to fix
          src/Traits/RunsClusterOperations.php on lines 333..349

          Duplicated Code

          Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

          Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

          When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

          Tuning

          This issue has a mass of 99.

          We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

          The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

          If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

          See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

          Refactorings

          Further Reading

          Severity
          Category
          Status
          Source
          Language