sam002/yii2-otp

View on GitHub
src/widgets/OtpInit.php

Summary

Maintainability
B
6 hrs
Test Coverage

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

class OtpInit extends InputWidget
{

    /**
     * @var string
Severity: Minor
Found in src/widgets/OtpInit.php by phpmd

File OtpInit.php has 268 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Author: Semen Dubina
 * Date: 20.01.16
 * Time: 4:22
Severity: Minor
Found in src/widgets/OtpInit.php - About 2 hrs to fix

    Method initQr has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function initQr($text)
        {
    
            $level = ErrorCorrectionLevelInterface::QUARTILE;
            $type = PngWriter::class;
    Severity: Minor
    Found in src/widgets/OtpInit.php - About 1 hr to fix

      Method decorateQr has 26 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function decorateQr(QrCode $qrCode)
          {
      
              $foreColor = [0,0,0];
              $backColor = [255,255,255];
      Severity: Minor
      Found in src/widgets/OtpInit.php - About 1 hr to fix

        Function initQr has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function initQr($text)
            {
        
                $level = ErrorCorrectionLevelInterface::QUARTILE;
                $type = PngWriter::class;
        Severity: Minor
        Found in src/widgets/OtpInit.php - About 35 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 decorateQr has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
        Open

            private function decorateQr(QrCode $qrCode)
            {
        
                $foreColor = [0,0,0];
                $backColor = [255,255,255];
        Severity: Minor
        Found in src/widgets/OtpInit.php - About 35 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 checkParamOutfile has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            private function checkParamOutfile($outfile)
            {
                if(is_string($outfile) && !is_dir(dirname($outfile))) {
                    throw new InvalidConfigException('OtpInit::$qrParams[\'outfile\'] error ' . dirname($outfile) . ' is not dir');
                } elseif (!is_string($outfile) && $outfile !== false) {
        Severity: Minor
        Found in src/widgets/OtpInit.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

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

        class OtpInit extends InputWidget
        {
        
            /**
             * @var string
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpmd

        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

        Avoid using static access to class '\yii\helpers\FileHelper' in method 'checkParamOutfile'.
        Open

                        FileHelper::createDirectory($dir);
        Severity: Minor
        Found in src/widgets/OtpInit.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 '\yii\helpers\Html' in method 'renderWidget'.
        Open

                    echo Html::a($this->link, $this->otp->getProvisioningUri());
        Severity: Minor
        Found in src/widgets/OtpInit.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 '\BaconQrCode\Common\CharacterSetEci' in method 'checkParamEncoding'.
        Open

                if (CharacterSetEci::getCharacterSetECIByName($encoding) === null) {
        Severity: Minor
        Found in src/widgets/OtpInit.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 '\yii\helpers\FileHelper' in method 'checkParamLogo'.
        Open

                        FileHelper::createDirectory($dir);
        Severity: Minor
        Found in src/widgets/OtpInit.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 '\yii\helpers\Html' in method 'renderWidget'.
        Open

                echo Html::activeHiddenInput($this->model, $this->attribute, $this->options);
        Severity: Minor
        Found in src/widgets/OtpInit.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

        There must be no space before the colon in a CASE statement
        Open

                    case JpgWriter::class :
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        There must be no space before the colon in a CASE statement
        Open

                    case PngWriter::class :
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        There must be no space before the colon in a CASE statement
        Open

                    case SvgWriter::class :
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        There must be no space before the colon in a CASE statement
        Open

                    case EpsWriter::class :
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Line exceeds 120 characters; contains 122 characters
        Open

                        $img = '<img src=' . $imgSrc . base64_encode($this->generateQr($this->otp->getProvisioningUri())) . ' />';
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Line exceeds 120 characters; contains 123 characters
        Open

                    throw new InvalidConfigException('OtpInit::$qrParams[\'outfile\'] error ' . dirname($outfile) . ' is not dir');
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Line exceeds 120 characters; contains 122 characters
        Open

                        $img = '<img src=' . $imgSrc . base64_encode($this->generateQr($this->otp->getProvisioningUri())) . ' />';
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Expected 0 spaces after opening bracket; newline found
        Open

                if(
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Expected 1 space after IF keyword; 0 found
        Open

                if(is_string($outfile) && !is_dir(dirname($outfile))) {
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Expected 1 space after IF keyword; 0 found
        Open

                if($outfile === false) {
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Expected 1 space after IF keyword; 0 found
        Open

                if(
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        Expected 1 space after IF keyword; 0 found
        Open

                if(!is_subclass_of($type, WriterInterface::class)) {
        Severity: Minor
        Found in src/widgets/OtpInit.php by phpcodesniffer

        There are no issues that match your filters.

        Category
        Status