VSVverkeerskunde/gvq-api

View on GitHub
src/Mail/Service/SwiftMailService.php

Summary

Maintainability
C
1 day
Test Coverage

Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
Open

        Swift_Mailer $swiftMailer,
        Twig_Environment $twig,
        TranslatorInterface $translator,
        UrlGeneratorInterface $urlGenerator,
        string $projectDir,
Severity: Minor
Found in src/Mail/Service/SwiftMailService.php - About 45 mins to fix

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

    class SwiftMailService implements MailService
    {
        /**
         * @var Swift_Mailer
         */
    Severity: Minor
    Found in src/Mail/Service/SwiftMailService.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 '\Swift_Attachment' in method 'sendKickOffMailAfterLaunch'.
    Open

            $message->attach(Swift_Attachment::fromPath($documentPath));
    Severity: Minor
    Found in src/Mail/Service/SwiftMailService.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

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

            } else {
                $documentPath = $this->projectDir . '/public/documents/nl/'.$documentName;
            }
    Severity: Minor
    Found in src/Mail/Service/SwiftMailService.php by phpmd

    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 using static access to class '\Swift_Attachment' in method 'sendKickOffMail'.
    Open

            $message->attach(Swift_Attachment::fromPath($documentPath));
    Severity: Minor
    Found in src/Mail/Service/SwiftMailService.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

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

            } else {
                $documentPath = $this->projectDir . '/public/documents/nl/'.$documentName;
            }
    Severity: Minor
    Found in src/Mail/Service/SwiftMailService.php by phpmd

    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

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

            } else {
                return 'Briefing voor bedrijven 2021.pdf';
            }
    Severity: Minor
    Found in src/Mail/Service/SwiftMailService.php by phpmd

    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

    Remove this unused private "getTextTemplate" method.
    Open

        private function getTextTemplate(Language $language, string $templateName): string

    private methods that are never executed are dead code: unnecessary, inoperative code that should be removed. Cleaning out dead code decreases the size of the maintained codebase, making it easier to understand the program and preventing bugs from being introduced.

    Noncompliant Code Example

    public class Foo
    {
      private function Foo() {}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.
    
      public static function doSomething()
      {
        $foo = new Foo();
        ...
      }
    
      private function unusedPrivateFunction() {  // Noncompliant
      }
    }
    

    Compliant Solution

    public class Foo
    {
      private function Foo(){}   // Compliant, private empty constructor intentionally used to prevent any direct instantiation of a class.
    
      public static function doSomething()
      {
        $foo = new Foo();
      }
    }
    

    See

    Define a constant instead of duplicating this literal "registration" 3 times.
    Open

                'registration' => $registration,
    Severity: Critical
    Found in src/Mail/Service/SwiftMailService.php by sonar-php

    Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.

    On the other hand, constants can be referenced from many places, but only need to be updated in a single place.

    Noncompliant Code Example

    With the default threshold of 3:

    function run() {
      prepare('action1');                              // Non-Compliant - 'action1' is duplicated 3 times
      execute('action1');
      release('action1');
    }
    

    Compliant Solution

    ACTION_1 = 'action1';
    
    function run() {
      prepare(ACTION_1);
      execute(ACTION_1);
      release(ACTION_1);
    }
    

    Exceptions

    To prevent generating some false-positives, literals having less than 5 characters are excluded.

    Avoid unused private methods such as 'getTextTemplate'.
    Open

        private function getTextTemplate(Language $language, string $templateName): string
        {
            return 'mails/'.$templateName.'.'.$language->toNative().'.text.twig';
        }
    Severity: Minor
    Found in src/Mail/Service/SwiftMailService.php by phpmd

    UnusedPrivateMethod

    Since: 0.2

    Unused Private Method detects when a private method is declared but is unused.

    Example

    class Something
    {
        private function foo() {} // unused
    }

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

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

        public function sendKickOffMailAfterLaunch(Registration $registration): void
        {
            $subjectId = 'Kickoff.after.launch.mail.subject';
            $templateName = 'kick_off_after_launch';
            $templateParameters = $this->generateKickOffTemplateParameters($registration);
    Severity: Major
    Found in src/Mail/Service/SwiftMailService.php and 1 other location - About 3 hrs to fix
    src/Mail/Service/SwiftMailService.php on lines 151..171

    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 158.

    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 sendKickOffMail(Registration $registration): void
        {
            $subjectId = 'Kickoff.mail.subject';
            $templateName = 'kick_off';
            $templateParameters = $this->generateKickOffTemplateParameters($registration);
    Severity: Major
    Found in src/Mail/Service/SwiftMailService.php and 1 other location - About 3 hrs to fix
    src/Mail/Service/SwiftMailService.php on lines 125..145

    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 158.

    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

    There are no issues that match your filters.

    Category
    Status