phug-php/watcher

View on GitHub
src/Phug/WatcherExtension.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method getDocumentEvents has 29 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function getDocumentEvents($browserReloadPort)
    {
        if (!$browserReloadPort) {
            return [];
        }
Severity: Minor
Found in src/Phug/WatcherExtension.php - About 1 hr to fix

    Function getDocumentEvents has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getDocumentEvents($browserReloadPort)
        {
            if (!$browserReloadPort) {
                return [];
            }
    Severity: Minor
    Found in src/Phug/WatcherExtension.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 using static access to class 'Phug\Phug' in method 'getOption'.
    Open

                : (Phug::hasOption($name) ? Phug::getOption($name) : null)
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class 'Phug\Phug' in method 'getOption'.
    Open

                : (Phug::hasOption($name) ? Phug::getOption($name) : null)
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class 'Phug\Phug' in method 'watch'.
    Open

                        return Phug::cacheFile($path);
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid using static access to class 'Phug\Phug' in method 'getOption'.
    Open

            $options = Phug::getOptions();
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phpmd

    StaticAccess

    Since: 1.4.0

    Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

    Example

    class Foo
    {
        public function bar()
        {
            Bar::baz();
        }
    }

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

    Avoid unused parameters such as '$resource'.
    Open

            $watcher->setChangeEventCallback(function ($event, $resource, $path) {
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Avoid unused parameters such as '$event'.
    Open

            $watcher->setChangeEventCallback(function ($event, $resource, $path) {
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phpmd

    UnusedFormalParameter

    Since: 0.2

    Avoid passing parameters to methods or constructors and then not using those parameters.

    Example

    class Foo
    {
        private function bar($howdy)
        {
            // $howdy is not used
        }
    }

    Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

    Possibly zero references to use statement for classlike/namespace DocumentNode (\Phug\Parser\Node\DocumentNode)
    Open

    use Phug\Parser\Node\DocumentNode;
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phan

    Call to method __construct from undeclared class \Phug\Parser\Node\ElementNode
    Open

                $reloadScript = new ElementNode($document->getToken());
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Checking instanceof against undeclared class \Phug\Parser\Node\ElementNode
    Open

                    if ($child instanceof ElementNode && strtolower($child->getName()) === 'body') {
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Class extends undeclared class \Phug\AbstractExtension
    Open

    class WatcherExtension extends AbstractExtension
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method appendChild from undeclared class \Phug\Parser\Node\ElementNode
    Open

                $reloadScript->appendChild($code);
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method getRenderer from undeclared class \Phug\Phug
    Open

                    $sandbox = Phug::getRenderer()->getNewSandBox(function () use ($path) {
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Checking instanceof against undeclared class \Phug\Parser\Node\ElementNode
    Open

                    if ($child instanceof ElementNode && strtolower($child->getName()) === 'html') {
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method setName from undeclared class \Phug\Parser\Node\ElementNode
    Open

                $reloadScript->setName('script');
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method getName from undeclared class \Phug\Parser\Node\ElementNode
    Open

                    if ($child instanceof ElementNode && strtolower($child->getName()) === 'html') {
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method setValue from undeclared class \Phug\Parser\Node\TextNode
    Open

                $code->setValue("window.onload = function () { $addScript };");
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Parameter $event has undeclared type \Phug\Parser\Event\NodeEvent
    Open

            return [function (NodeEvent $event) use ($browserReloadPort) {
    Severity: Minor
    Found in src/Phug/WatcherExtension.php by phan

    Call to method getName from undeclared class \Phug\Parser\Node\ElementNode
    Open

                    if ($child instanceof ElementNode && strtolower($child->getName()) === 'body') {
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method cacheFile from undeclared class \Phug\Phug
    Open

                        return Phug::cacheFile($path);
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method getNode from undeclared class \Phug\Parser\Event\NodeEvent
    Open

                $document = $event->getNode();
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method getOptions from undeclared class \Phug\Phug
    Open

            $options = Phug::getOptions();
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method getOption from undeclared class \Phug\Phug
    Open

                : (Phug::hasOption($name) ? Phug::getOption($name) : null)
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method hasOption from undeclared class \Phug\Phug
    Open

                : (Phug::hasOption($name) ? Phug::getOption($name) : null)
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    Call to method __construct from undeclared class \Phug\Parser\Node\TextNode
    Open

                $code = new TextNode();
    Severity: Critical
    Found in src/Phug/WatcherExtension.php by phan

    There are no issues that match your filters.

    Category
    Status