garrettw/Dice

View on GitHub

Showing 15 of 15 total issues

Function loadV1 has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    private function loadV1(\SimpleXmlElement $xml, \Dice\Dice $dice)
    {
        foreach ($xml as $key => $value) {
            $rule = $dice->getRule((string) $value->name);

Severity: Minor
Found in src/Loader/Xml.php - About 5 hrs 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

Function getParams has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring.
Open

    private function getParams(\ReflectionMethod $method, array $rule)
    {
        $paramInfo = []; // Caches some information about the parameter so (slow) reflection isn't needed every time
        foreach ($method->getParameters() as $param) {
            // get the class hint of each param, if there is one
Severity: Minor
Found in src/Dice.php - About 4 hrs 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

Function loadV2 has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
Open

    private function loadV2(\SimpleXmlElement $xml, \Dice\Dice $dice)
    {
        foreach ($xml as $key => $value) {
            $rule = $dice->getRule((string) $value->name);

Severity: Minor
Found in src/Loader/Xml.php - About 4 hrs 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

Function create has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    public function create($classname, array $args = [], array $share = [])
    {
        if (!empty($this->instances[$classname])) {
            // we've already created a shared instance so return it to save the closure call.
            return $this->instances[$classname];
Severity: Minor
Found in src/Dice.php - About 3 hrs 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 create has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function create($classname, array $args = [], array $share = [])
    {
        if (!empty($this->instances[$classname])) {
            // we've already created a shared instance so return it to save the closure call.
            return $this->instances[$classname];
Severity: Major
Found in src/Dice.php - About 2 hrs to fix

    Method getParams has 52 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function getParams(\ReflectionMethod $method, array $rule)
        {
            $paramInfo = []; // Caches some information about the parameter so (slow) reflection isn't needed every time
            foreach ($method->getParameters() as $param) {
                // get the class hint of each param, if there is one
    Severity: Major
    Found in src/Dice.php - About 2 hrs to fix

      Method loadV1 has 43 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function loadV1(\SimpleXmlElement $xml, \Dice\Dice $dice)
          {
              foreach ($xml as $key => $value) {
                  $rule = $dice->getRule((string) $value->name);
      
      
      Severity: Minor
      Found in src/Loader/Xml.php - About 1 hr to fix

        Method loadV2 has 36 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function loadV2(\SimpleXmlElement $xml, \Dice\Dice $dice)
            {
                foreach ($xml as $key => $value) {
                    $rule = $dice->getRule((string) $value->name);
        
        
        Severity: Minor
        Found in src/Loader/Xml.php - About 1 hr to fix

          Function expand has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              private function expand($param, array $share = [], $createFromString = false)
              {
                  if (!\is_array($param)) {
                      // doesn't need any processing
                      return (is_string($param) && $createFromString) ? $this->create($param) : $param;
          Severity: Minor
          Found in src/Dice.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

          Avoid too many return statements within this method.
          Open

                          return $object;
          Severity: Major
          Found in src/Dice.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return \call_user_func($param[self::INSTANCE]);
            Severity: Major
            Found in src/Dice.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                      return $this->cache[$classname]($args, $share);
              Severity: Major
              Found in src/Dice.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return $this->create($param[self::INSTANCE], (is_array($args)) ? \array_merge($args, $share) : $share);
                Severity: Major
                Found in src/Dice.php - About 30 mins to fix

                  Function addRule has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function addRule($classname, $rule)
                      {
                          if (isset($rule['instanceOf'])
                              && \is_string($rule['instanceOf'])
                              && (!\array_key_exists('inherit', $rule) || $rule['inherit'] === true)
                  Severity: Minor
                  Found in src/Dice.php - About 25 mins 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

                  Function getRule has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      public function getRule($name)
                      {
                          // first, check for exact match
                          $normalname = self::normalizeName($name);
                  
                  
                  Severity: Minor
                  Found in src/Dice.php - About 25 mins 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

                  Severity
                  Category
                  Status
                  Source
                  Language