YetiForceCompany/YetiForceCRM

View on GitHub
tests/Init/LanguageFilesTest.php

Summary

Maintainability
A
25 mins
Test Coverage
A
100%

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

    public function testLoadFiles()
    {
        static::assertTrue(\App\Installer\Languages::download('pl-PL'), 'Error while downloading the language "pl-PL"');
        $parser = new \Seld\JsonLint\JsonParser();
        foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'languages', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
Severity: Minor
Found in tests/Init/LanguageFilesTest.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

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

        foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'languages', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
Severity: Minor
Found in tests/Init/LanguageFilesTest.php by phpmd

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 '36', column '16').
Open

                    throw new \Exception("File: {$item->getPathname()}:" . PHP_EOL . $e->getMessage());
Severity: Minor
Found in tests/Init/LanguageFilesTest.php by phpmd

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 '29', column '17').
Open

        $parser = new \Seld\JsonLint\JsonParser();
Severity: Minor
Found in tests/Init/LanguageFilesTest.php by phpmd

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 '30', column '59').
Open

        foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'languages', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
Severity: Minor
Found in tests/Init/LanguageFilesTest.php by phpmd

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

Avoid using static access to class '\App\Installer\Languages' in method 'testLoadFiles'.
Open

        static::assertTrue(\App\Installer\Languages::download('pl-PL'), 'Error while downloading the language "pl-PL"');
Severity: Minor
Found in tests/Init/LanguageFilesTest.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

Define and throw a dedicated exception instead of using a generic one.
Open

                    throw new \Exception("File: {$item->getPathname()}:" . PHP_EOL . $e->getMessage());
Severity: Major
Found in tests/Init/LanguageFilesTest.php by sonar-php

If you throw a general exception type, such as ErrorException, RuntimeException, or Exception in a library or framework, it forces consumers to catch all exceptions, including unknown exceptions that they do not know how to handle.

Instead, either throw a subtype that already exists in the Standard PHP Library, or create your own type that derives from Exception.

Noncompliant Code Example

throw new Exception();  // Noncompliant

Compliant Solution

throw new InvalidArgumentException();
// or
throw new UnexpectedValueException();

See

Avoid unused local variables such as '$iterator'.
Open

        foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'languages', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
Severity: Minor
Found in tests/Init/LanguageFilesTest.php by phpmd

UnusedLocalVariable

Since: 0.2

Detects when a local variable is declared and/or assigned, but not used.

Example

class Foo {
    public function doSomething()
    {
        $i = 5; // Unused
    }
}

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

Call to method getMessage from undeclared class \Seld\JsonLint\ParsingException
Open

                    throw new \Exception("File: {$item->getPathname()}:" . PHP_EOL . $e->getMessage());
Severity: Critical
Found in tests/Init/LanguageFilesTest.php by phan

Static call to undeclared method \Tests\Init\LanguageFilesTest::assertNotEmpty
Open

                    static::assertNotEmpty($parser->parse(file_get_contents($item->getPathname())));
Severity: Critical
Found in tests/Init/LanguageFilesTest.php by phan

Call to method parse from undeclared class \Seld\JsonLint\JsonParser
Open

                    static::assertNotEmpty($parser->parse(file_get_contents($item->getPathname())));
Severity: Critical
Found in tests/Init/LanguageFilesTest.php by phan

Catching undeclared class \Seld\JsonLint\ParsingException
Open

                } catch (\Seld\JsonLint\ParsingException $e) {
Severity: Critical
Found in tests/Init/LanguageFilesTest.php by phan

Call to method __construct from undeclared class \Seld\JsonLint\JsonParser
Open

        $parser = new \Seld\JsonLint\JsonParser();
Severity: Critical
Found in tests/Init/LanguageFilesTest.php by phan

Static call to undeclared method \Tests\Init\LanguageFilesTest::assertTrue
Open

        static::assertTrue(\App\Installer\Languages::download('pl-PL'), 'Error while downloading the language "pl-PL"');
Severity: Critical
Found in tests/Init/LanguageFilesTest.php by phan

Spaces must be used to indent lines; tabs are not allowed
Open

                }

Spaces must be used to indent lines; tabs are not allowed
Open

        foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'languages', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {

Spaces must be used to indent lines; tabs are not allowed
Open

                    throw new \Exception("File: {$item->getPathname()}:" . PHP_EOL . $e->getMessage());

Spaces must be used to indent lines; tabs are not allowed
Open

                try {

Spaces must be used to indent lines; tabs are not allowed
Open

     * Testing language files.

Spaces must be used to indent lines; tabs are not allowed
Open

    {

Spaces must be used to indent lines; tabs are not allowed
Open

        $parser = new \Seld\JsonLint\JsonParser();

Spaces must be used to indent lines; tabs are not allowed
Open

            }

Spaces must be used to indent lines; tabs are not allowed
Open

     */

Spaces must be used to indent lines; tabs are not allowed
Open

                    // @codeCoverageIgnoreStart

Spaces must be used to indent lines; tabs are not allowed
Open

                // @codeCoverageIgnoreEnd

Spaces must be used to indent lines; tabs are not allowed
Open

    public function testLoadFiles()

Spaces must be used to indent lines; tabs are not allowed
Open

        }

Spaces must be used to indent lines; tabs are not allowed
Open

    }

Line exceeds 120 characters; contains 237 characters
Open

        foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(ROOT_DIRECTORY . \DIRECTORY_SEPARATOR . 'languages', \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {

Spaces must be used to indent lines; tabs are not allowed
Open

    /**

Spaces must be used to indent lines; tabs are not allowed
Open

        static::assertTrue(\App\Installer\Languages::download('pl-PL'), 'Error while downloading the language "pl-PL"');

Spaces must be used to indent lines; tabs are not allowed
Open

            if ($item->isFile()) {

Spaces must be used to indent lines; tabs are not allowed
Open

                } catch (\Seld\JsonLint\ParsingException $e) {

Spaces must be used to indent lines; tabs are not allowed
Open

                    static::assertNotEmpty($parser->parse(file_get_contents($item->getPathname())));

There are no issues that match your filters.

Category
Status