Formula9/Framework

View on GitHub
F9/Providers/F9WebProfilerServiceProvider.php

Summary

Maintainability
F
3 days
Test Coverage

Method register has 192 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function register(Container $app)
    {
        $app['profiler.mount_prefix'] = '/_profiler';
        $app->extend('dispatcher', function ($dispatcher, $app) {
            return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);
Severity: Major
Found in F9/Providers/F9WebProfilerServiceProvider.php - About 7 hrs to fix

    Function register has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
    Open

        public function register(Container $app)
        {
            $app['profiler.mount_prefix'] = '/_profiler';
            $app->extend('dispatcher', function ($dispatcher, $app) {
                return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);
    Severity: Minor
    Found in F9/Providers/F9WebProfilerServiceProvider.php - About 2 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

    File F9WebProfilerServiceProvider.php has 276 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    /*
     * This file is part of the Silex framework.
     *
    Severity: Minor
    Found in F9/Providers/F9WebProfilerServiceProvider.php - About 2 hrs to fix

      Avoid too many return statements within this method.
      Open

                          return new TwigDataCollector($app['twig.profiler.profile']);
      Severity: Major
      Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                        return $twig;
        Severity: Major
        Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

          Avoid too many return statements within this method.
          Open

                      return $profiler;
          Severity: Major
          Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return new WebDebugToolbarListener($app['twig'], $app['web_profiler.debug_toolbar.intercept_redirects'], $mode, $app['web_profiler.debug_toolbar.position'], $app['url_generator']);
            Severity: Major
            Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return $twig;
              Severity: Major
              Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return new ResolvedTypeFactoryDataCollectorProxy($factory, $app['data_collectors']['form']($app));
                Severity: Major
                Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return new FileProfilerStorage('file:' . $app['profiler.cache_dir']);
                  Severity: Major
                  Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return $extensions;
                    Severity: Major
                    Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return new \Twig_Profiler_Profile();
                      Severity: Major
                      Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                        return $collectors;
                        Severity: Major
                        Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return $collectors;
                          Severity: Major
                          Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                        return new ExceptionController($app['profiler'], $app['twig'], $app['debug']);
                            Severity: Major
                            Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                          return $loader;
                              Severity: Major
                              Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                    return new AjaxDataCollector();
                                Severity: Major
                                Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                                  return new DumpListener($app['var_dumper.cloner'], $app['var_dumper.data_collector']);
                                  Severity: Major
                                  Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                    return $collectors;
                                    Severity: Major
                                    Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                          return Yaml::dump($var);
                                      Severity: Major
                                      Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return new ProfilerController($app['url_generator'], $app['profiler'], $app['twig'], $app['data_collector.templates'], $app['web_profiler.debug_toolbar.position']);
                                        Severity: Major
                                        Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                                  return $app['var_dumper.data_collector'] = new DumpDataCollector($app['stopwatch'], NULL, $app['charset'], $app['request_stack'], $dumper);
                                          Severity: Major
                                          Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                            return $templates;
                                            Severity: Major
                                            Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                                  return Yaml::dump($var);
                                              Severity: Major
                                              Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                                return $collectors;
                                                Severity: Major
                                                Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                                      return new $sec_data_collector($app['security.token_storage'], $roleHierarchy, $logoutUrlGenerator);
                                                  Severity: Major
                                                  Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                return dirname(dirname($r->getFileName())) . '/Resources/views';
                                                    Severity: Major
                                                    Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return new Stopwatch();
                                                      Severity: Major
                                                      Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                        Avoid too many return statements within this method.
                                                        Open

                                                                            return dirname($file) . '/Resources/views';
                                                        Severity: Major
                                                        Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                          Avoid too many return statements within this method.
                                                          Open

                                                                      return new RouterController($app['profiler'], $app['twig'], $app['request_matcher'] ?? NULL, $app['routes']);
                                                          Severity: Major
                                                          Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                            Avoid too many return statements within this method.
                                                            Open

                                                                            $collectors['form'] = function ($app) { return new FormDataCollector($app['data_collectors.form.extractor']); };
                                                            Severity: Major
                                                            Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                              Avoid too many return statements within this method.
                                                              Open

                                                                              return $collectors;
                                                              Severity: Major
                                                              Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                                Avoid too many return statements within this method.
                                                                Open

                                                                                return $loader;
                                                                Severity: Major
                                                                Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                                  Avoid too many return statements within this method.
                                                                  Open

                                                                                  return dirname(dirname($r->getFileName())) . '/Resources/views';
                                                                  Severity: Major
                                                                  Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                                    Avoid too many return statements within this method.
                                                                    Open

                                                                                    return new ProfilerListener($app['profiler'], $app['request_stack'], $app['profiler.request_matcher'], $app['profiler.only_exceptions'], $app['profiler.only_master_requests']);
                                                                    Severity: Major
                                                                    Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                                      Avoid too many return statements within this method.
                                                                      Open

                                                                                      return new ProfilerListener($app['profiler'], $app['profiler.request_matcher'], $app['profiler.only_exceptions'], $app['profiler.only_master_requests'], $app['request_stack']);
                                                                      Severity: Major
                                                                      Found in F9/Providers/F9WebProfilerServiceProvider.php - About 30 mins to fix

                                                                        The method register() has 254 lines of code. Current threshold is set to 100. Avoid really long methods.
                                                                        Open

                                                                            public function register(Container $app)
                                                                            {
                                                                                $app['profiler.mount_prefix'] = '/_profiler';
                                                                                $app->extend('dispatcher', function ($dispatcher, $app) {
                                                                                    return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);

                                                                        The method register() has an NPath complexity of 1548288. The configured NPath complexity threshold is 200.
                                                                        Open

                                                                            public function register(Container $app)
                                                                            {
                                                                                $app['profiler.mount_prefix'] = '/_profiler';
                                                                                $app->extend('dispatcher', function ($dispatcher, $app) {
                                                                                    return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);

                                                                        NPathComplexity

                                                                        Since: 0.1

                                                                        The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

                                                                        Example

                                                                        class Foo {
                                                                            function bar() {
                                                                                // lots of complicated code
                                                                            }
                                                                        }

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

                                                                        The method register() has a Cyclomatic Complexity of 26. The configured cyclomatic complexity threshold is 10.
                                                                        Open

                                                                            public function register(Container $app)
                                                                            {
                                                                                $app['profiler.mount_prefix'] = '/_profiler';
                                                                                $app->extend('dispatcher', function ($dispatcher, $app) {
                                                                                    return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);

                                                                        CyclomaticComplexity

                                                                        Since: 0.1

                                                                        Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

                                                                        Example

                                                                        // Cyclomatic Complexity = 11
                                                                        class Foo {
                                                                        1   public function example() {
                                                                        2       if ($a == $b) {
                                                                        3           if ($a1 == $b1) {
                                                                                        fiddle();
                                                                        4           } elseif ($a2 == $b2) {
                                                                                        fiddle();
                                                                                    } else {
                                                                                        fiddle();
                                                                                    }
                                                                        5       } elseif ($c == $d) {
                                                                        6           while ($c == $d) {
                                                                                        fiddle();
                                                                                    }
                                                                        7        } elseif ($e == $f) {
                                                                        8           for ($n = 0; $n < $h; $n++) {
                                                                                        fiddle();
                                                                                    }
                                                                                } else {
                                                                                    switch ($z) {
                                                                        9               case 1:
                                                                                            fiddle();
                                                                                            break;
                                                                        10              case 2:
                                                                                            fiddle();
                                                                                            break;
                                                                        11              case 3:
                                                                                            fiddle();
                                                                                            break;
                                                                                        default:
                                                                                            fiddle();
                                                                                            break;
                                                                                    }
                                                                                }
                                                                            }
                                                                        }

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

                                                                        The class F9WebProfilerServiceProvider has a coupling between objects value of 41. Consider to reduce the number of dependencies under 13.
                                                                        Open

                                                                        class F9WebProfilerServiceProvider implements ServiceProviderInterface, ControllerProviderInterface, BootableProvider, EventListenerProviderInterface
                                                                        {
                                                                            public function boot($app)
                                                                            {
                                                                                $app->mount($app['profiler.mount_prefix'], $this->connect($app));

                                                                        CouplingBetweenObjects

                                                                        Since: 1.1.0

                                                                        A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

                                                                        Example

                                                                        class Foo {
                                                                            /**
                                                                             * @var \foo\bar\X
                                                                             */
                                                                            private $x = null;
                                                                        
                                                                            /**
                                                                             * @var \foo\bar\Y
                                                                             */
                                                                            private $y = null;
                                                                        
                                                                            /**
                                                                             * @var \foo\bar\Z
                                                                             */
                                                                            private $z = null;
                                                                        
                                                                            public function setFoo(\Foo $foo) {}
                                                                            public function setBar(\Bar $bar) {}
                                                                            public function setBaz(\Baz $baz) {}
                                                                        
                                                                            /**
                                                                             * @return \SplObjectStorage
                                                                             * @throws \OutOfRangeException
                                                                             * @throws \InvalidArgumentException
                                                                             * @throws \ErrorException
                                                                             */
                                                                            public function process(\Iterator $it) {}
                                                                        
                                                                            // ...
                                                                        }

                                                                        Source https://phpmd.org/rules/design.html#couplingbetweenobjects

                                                                        Missing class import via use statement (line '171', column '28').
                                                                        Open

                                                                                        return new \Twig_Profiler_Profile();

                                                                        MissingImport

                                                                        Since: 2.7.0

                                                                        Importing all external classes in a file through use statements makes them clearly visible.

                                                                        Example

                                                                        function make() {
                                                                            return new \stdClass();
                                                                        }

                                                                        Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                        Missing class import via use statement (line '72', column '23').
                                                                        Open

                                                                                    throw new \LogicException('You must enable the ServiceController service provider to be able to use the WebProfiler.');

                                                                        MissingImport

                                                                        Since: 2.7.0

                                                                        Importing all external classes in a file through use statements makes them clearly visible.

                                                                        Example

                                                                        function make() {
                                                                            return new \stdClass();
                                                                        }

                                                                        Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                        Missing class import via use statement (line '238', column '53').
                                                                        Open

                                                                                        $twig->addFilter('yaml_encode', new \Twig_SimpleFilter('yaml_encode', function (array $var) {

                                                                        MissingImport

                                                                        Since: 2.7.0

                                                                        Importing all external classes in a file through use statements makes them clearly visible.

                                                                        Example

                                                                        function make() {
                                                                            return new \stdClass();
                                                                        }

                                                                        Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                        Missing class import via use statement (line '242', column '55').
                                                                        Open

                                                                                        $twig->addFunction('yaml_encode', new \Twig_SimpleFunction('yaml_encode', function (array $var) {

                                                                        MissingImport

                                                                        Since: 2.7.0

                                                                        Importing all external classes in a file through use statements makes them clearly visible.

                                                                        Example

                                                                        function make() {
                                                                            return new \stdClass();
                                                                        }

                                                                        Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                        Missing class import via use statement (line '232', column '26').
                                                                        Open

                                                                                        $r = new \ReflectionClass('Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector');

                                                                        MissingImport

                                                                        Since: 2.7.0

                                                                        Importing all external classes in a file through use statements makes them clearly visible.

                                                                        Example

                                                                        function make() {
                                                                            return new \stdClass();
                                                                        }

                                                                        Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                        Missing class import via use statement (line '330', column '22').
                                                                        Open

                                                                                    $r = new \ReflectionClass('Symfony\Bundle\WebProfilerBundle\EventListener\WebDebugToolbarListener');

                                                                        MissingImport

                                                                        Since: 2.7.0

                                                                        Importing all external classes in a file through use statements makes them clearly visible.

                                                                        Example

                                                                        function make() {
                                                                            return new \stdClass();
                                                                        }

                                                                        Source http://phpmd.org/rules/cleancode.html#MissingImport

                                                                        The method register uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
                                                                        Open

                                                                                    else {
                                                                                        /** @noinspection PhpParamsInspection */
                                                                                        return new ProfilerListener($app['profiler'], $app['profiler.request_matcher'], $app['profiler.only_exceptions'], $app['profiler.only_master_requests'], $app['request_stack']);
                                                                                    }

                                                                        ElseExpression

                                                                        Since: 1.4.0

                                                                        An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.

                                                                        Example

                                                                        class Foo
                                                                        {
                                                                            public function bar($flag)
                                                                            {
                                                                                if ($flag) {
                                                                                    // one branch
                                                                                } else {
                                                                                    // another branch
                                                                                }
                                                                            }
                                                                        }

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

                                                                        Avoid assigning values to variables in if clauses and the like (line '341', column '21').
                                                                        Open

                                                                            public function register(Container $app)
                                                                            {
                                                                                $app['profiler.mount_prefix'] = '/_profiler';
                                                                                $app->extend('dispatcher', function ($dispatcher, $app) {
                                                                                    return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);

                                                                        IfStatementAssignment

                                                                        Since: 2.7.0

                                                                        Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

                                                                        Example

                                                                        class Foo
                                                                        {
                                                                            public function bar($flag)
                                                                            {
                                                                                if ($foo = 'bar') { // possible typo
                                                                                    // ...
                                                                                }
                                                                                if ($baz = 0) { // always false
                                                                                    // ...
                                                                                }
                                                                            }
                                                                        }

                                                                        Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

                                                                        Avoid variables with short names like $r. Configured minimum length is 3.
                                                                        Open

                                                                                        $r = new \ReflectionClass('Symfony\Bundle\SecurityBundle\DataCollector\SecurityDataCollector');

                                                                        ShortVariable

                                                                        Since: 0.2

                                                                        Detects when a field, local, or parameter has a very short name.

                                                                        Example

                                                                        class Something {
                                                                            private $q = 15; // VIOLATION - Field
                                                                            public static function main( array $as ) { // VIOLATION - Formal
                                                                                $r = 20 + $this->q; // VIOLATION - Local
                                                                                for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                                                                                    $r += $this->q;
                                                                                }
                                                                            }
                                                                        }

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

                                                                        The variable $sec_data_collector is not named in camelCase.
                                                                        Open

                                                                            public function register(Container $app)
                                                                            {
                                                                                $app['profiler.mount_prefix'] = '/_profiler';
                                                                                $app->extend('dispatcher', function ($dispatcher, $app) {
                                                                                    return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);

                                                                        CamelCaseVariableName

                                                                        Since: 0.2

                                                                        It is considered best practice to use the camelCase notation to name variables.

                                                                        Example

                                                                        class ClassName {
                                                                            public function doSomething() {
                                                                                $data_module = new DataModule();
                                                                            }
                                                                        }

                                                                        Source

                                                                        The variable $sec_data_collector is not named in camelCase.
                                                                        Open

                                                                            public function register(Container $app)
                                                                            {
                                                                                $app['profiler.mount_prefix'] = '/_profiler';
                                                                                $app->extend('dispatcher', function ($dispatcher, $app) {
                                                                                    return new TraceableEventDispatcher($dispatcher, $app['stopwatch'], $app['logger']);

                                                                        CamelCaseVariableName

                                                                        Since: 0.2

                                                                        It is considered best practice to use the camelCase notation to name variables.

                                                                        Example

                                                                        class ClassName {
                                                                            public function doSomething() {
                                                                                $data_module = new DataModule();
                                                                            }
                                                                        }

                                                                        Source

                                                                        There are no issues that match your filters.

                                                                        Category
                                                                        Status