open-orchestra/open-orchestra-cms-bundle

View on GitHub
Backoffice/Tests/Form/DataTransformer/CsvToReferenceKeywordTransformerTest.php

Summary

Maintainability
F
3 days
Test Coverage

Method setUp has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function setUp()
    {
        $this->keywordToDocumentManager = Phake::mock('OpenOrchestra\Backoffice\Manager\KeywordToDocumentManager');
        $this->keywordRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface');

Avoid using static access to class '\Phake' in method 'setUp'.
Open

        $this->keywordRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface');

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 '\Phake' in method 'setUp'.
Open

        $this->keywordRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface');

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 '\Phake' in method 'setUp'.
Open

        $t2Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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 '\Phake' in method 'setUp'.
Open

        $this->keywordToDocumentManager = Phake::mock('OpenOrchestra\Backoffice\Manager\KeywordToDocumentManager');

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 '\Phake' in method 'setUp'.
Open

        $catX2Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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 '\Phake' in method 'setUp'.
Open

        $t3Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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 '\Phake' in method 'setUp'.
Open

        $t1Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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 '\Phake' in method 'createKeywordsToInterface'.
Open

                $keywordsInterface[$key] = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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 '\Phake' in method 'setUp'.
Open

        $catX1Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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 '\Phake' in method 'setUp'.
Open

        $notCreatedKeyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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 '\Phake' in method 'setUp'.
Open

        $this->keywordToDocumentManager = Phake::mock('OpenOrchestra\Backoffice\Manager\KeywordToDocumentManager');

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 '\Phake' in method 'setUp'.
Open

        $authorAAAKeyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

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

Call to method mock from undeclared class \Phake
Open

        $this->keywordToDocumentManager = Phake::mock('OpenOrchestra\Backoffice\Manager\KeywordToDocumentManager');

Call to method mock from undeclared class \Phake
Open

                $keywordsInterface[$key] = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method mock from undeclared class \Phake
Open

        $t2Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($notCreatedKeyword)->getLabel()->thenReturn('not_created_keyword');

Call to method toArray from undeclared class \Doctrine\Common\Collections\ArrayCollection
Open

        $this->assertSame($keywords, $this->transformer->reverseTransform($string)->toArray());

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Form\DataTransformer\CsvToReferenceKeywordTransformerTest::assertSame
Open

        $this->assertSame($expected, $this->transformer->transform(new ArrayCollection($keywords)));

Call to method mock from undeclared class \Phake
Open

        $catX2Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($t3Keyword)->getId()->thenReturn('fakeId[T3]');

Call to method mock from undeclared class \Phake
Open

        $this->keywordRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface');

Argument 1 (keywords) is \Doctrine\Common\Collections\ArrayCollection but \OpenOrchestra\Backoffice\Form\DataTransformer\CsvToReferenceKeywordTransformer::transform() takes string defined at /code/Backoffice/Form/DataTransformer/AbstractReferenceKeywordTransformer.php:38
Open

        $this->assertSame($expected, $this->transformer->transform(new ArrayCollection($keywords)));

Call to method when from undeclared class \Phake
Open

                Phake::when($keywordsInterface[$key])->getLabel()->thenReturn($keyword);

Call to method mock from undeclared class \Phake
Open

        $this->keywordRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface');

Call to method mock from undeclared class \Phake
Open

        $t1Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($t2Keyword)->getLabel()->thenReturn('T2');

Call to method mock from undeclared class \Phake
Open

        $this->keywordToDocumentManager = Phake::mock('OpenOrchestra\Backoffice\Manager\KeywordToDocumentManager');

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Form\DataTransformer\CsvToReferenceKeywordTransformerTest::assertSame
Open

        $this->assertSame($keywords, $this->transformer->reverseTransform($string)->toArray());

Call to method when from undeclared class \Phake
Open

        Phake::when($catX1Keyword)->getLabel()->thenReturn('cat:X1');

Call to method when from undeclared class \Phake
Open

        Phake::when($catX2Keyword)->getLabel()->thenReturn('cat:X2');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->keywordRepository)->find('fakeId[T1]')->thenReturn($t1Keyword);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->keywordRepository)->find('fakeId[T2]')->thenReturn($t2Keyword);

Call to method when from undeclared class \Phake
Open

        Phake::when($t1Keyword)->getId()->thenReturn('fakeId[T1]');

Call to method mock from undeclared class \Phake
Open

        $t3Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($t3Keyword)->getLabel()->thenReturn('T3');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->keywordToDocumentManager)->getDocument('not_created_keyword')->thenReturn($notCreatedKeyword);

Call to method mock from undeclared class \Phake
Open

        $catX1Keyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($catX1Keyword)->getId()->thenReturn('fakeId[cat:X1]');

Call to method when from undeclared class \Phake
Open

        Phake::when($catX2Keyword)->getId()->thenReturn('fakeId[cat:X2]');

Call to method mock from undeclared class \Phake
Open

        $notCreatedKeyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->keywordRepository)->find('fakeId[cat:X1]')->thenReturn($catX1Keyword);

Call to method __construct from undeclared class \Doctrine\Common\Collections\ArrayCollection
Open

        $this->assertSame($expected, $this->transformer->transform(new ArrayCollection($keywords)));

Call to method when from undeclared class \Phake
Open

                Phake::when($keywordsInterface[$key])->getId()->thenReturn('fakeId[' . $keyword . ']');

Call to method when from undeclared class \Phake
Open

                Phake::when($this->keywordToDocumentManager)->getDocument($keyword)->thenReturn($keywordsInterface[$key]);

Class extends undeclared class \OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractBaseTestCase
Open

class CsvToReferenceKeywordTransformerTest extends AbstractBaseTestCase

Call to method when from undeclared class \Phake
Open

        Phake::when($this->keywordRepository)->find('fakeId[author:AAA]')->thenReturn($authorAAAKeyword);

Call to method when from undeclared class \Phake
Open

                Phake::when($this->keywordRepository)->find('fakeId[' . $keyword . ']')->thenReturn($keywordsInterface[$key]);

Call to method when from undeclared class \Phake
Open

        Phake::when($t2Keyword)->getId()->thenReturn('fakeId[T2]');

Call to method mock from undeclared class \Phake
Open

        $authorAAAKeyword = Phake::mock('OpenOrchestra\ModelInterface\Model\KeywordInterface');

Call to method when from undeclared class \Phake
Open

        Phake::when($authorAAAKeyword)->getLabel()->thenReturn('author:AAA');

Call to method when from undeclared class \Phake
Open

        Phake::when($authorAAAKeyword)->getId()->thenReturn('fakeId[author:AAA]');

Call to method when from undeclared class \Phake
Open

        Phake::when($t1Keyword)->getLabel()->thenReturn('T1');

Call to method when from undeclared class \Phake
Open

        Phake::when($notCreatedKeyword)->getId()->thenReturn('fakeId[not_created_keyword]');

Call to method when from undeclared class \Phake
Open

        Phake::when($this->keywordRepository)->find('fakeId[cat:X2]')->thenReturn($catX2Keyword);

Call to method when from undeclared class \Phake
Open

        Phake::when($this->keywordRepository)->find('fakeId[T3]')->thenReturn($t3Keyword);

Call to undeclared method \OpenOrchestra\Backoffice\Tests\Form\DataTransformer\CsvToReferenceKeywordTransformerTest::assertInstanceOf
Open

        $this->assertInstanceOf('Symfony\Component\Form\DataTransformerInterface', $this->transformer);

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

    public function setUp()
    {
        $this->keywordToDocumentManager = Phake::mock('OpenOrchestra\Backoffice\Manager\KeywordToDocumentManager');
        $this->keywordRepository = Phake::mock('OpenOrchestra\ModelInterface\Repository\KeywordRepositoryInterface');

Backoffice/Tests/Form/DataTransformer/ConditionToReferenceKeywordTransformerTest.php on lines 24..63

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

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

Avoid excessively long variable names like $keywordToDocumentManager. Keep variable name length under 20.
Open

    protected $keywordToDocumentManager;

LongVariable

Since: 0.2

Detects when a field, formal or local variable is declared with a long name.

Example

class Something {
    protected $reallyLongIntName = -3; // VIOLATION - Field
    public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
        $otherReallyLongName = -5; // VIOLATION - Local
        for ($interestingIntIndex = 0; // VIOLATION - For
             $interestingIntIndex < 10;
             $interestingIntIndex++ ) {
        }
    }
}

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

Line exceeds 120 characters; contains 121 characters
Open

        Phake::when($this->keywordToDocumentManager)->getDocument('not_created_keyword')->thenReturn($notCreatedKeyword);

Line exceeds 120 characters; contains 125 characters
Open

        $this->transformer = new CsvToReferenceKeywordTransformer($this->keywordToDocumentManager, $this->keywordRepository);

Line exceeds 120 characters; contains 126 characters
Open

                Phake::when($this->keywordRepository)->find('fakeId[' . $keyword . ']')->thenReturn($keywordsInterface[$key]);

Line exceeds 120 characters; contains 122 characters
Open

                Phake::when($this->keywordToDocumentManager)->getDocument($keyword)->thenReturn($keywordsInterface[$key]);

There are no issues that match your filters.

Category
Status