GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Pull Request — master (#153)
by joseph
29:27
created

php$3 ➔ thereCanBeMultipleOfTheSameArchetypeInAnEntity()   B

Complexity

Conditions 1

Size

Total Lines 59

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 59
rs 8.8945
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A HasMoneyEmbeddableTraitLargeTest.php$2 ➔ getMoneyEmbeddable() 0 6 1
A HasMoneyEmbeddableTraitLargeTest.php$3 ➔ getPriceEmbeddable() 0 6 1

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Tests\Large\C\Entity\Embeddable\Traits\Financial;
4
5
use EdmondsCommerce\DoctrineStaticMeta\Entity\DataTransferObjects\AbstractEntityUpdateDto;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Interfaces\Objects\Financial\MoneyEmbeddableInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Objects\Financial\MoneyEmbeddable;
8
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Repositories\AbstractEntityRepository;
10
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractLargeTest;
11
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\AbstractTest;
12
use EdmondsCommerce\DoctrineStaticMeta\Tests\Assets\TestCodeGenerator;
13
use HasMoneyEmbeddableTraitLargeTest_ThereCanBeMultipleOfTheSameArchetypeInAnEntity_\Entity\Embeddable\Objects\Financial\PriceEmbeddable;
0 ignored issues
show
Bug introduced by
The type HasMoneyEmbeddableTraitL...nancial\PriceEmbeddable was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
14
use Money\Currency;
15
use Money\Money;
16
17
/**
18
 * @large
19
 * @covers \EdmondsCommerce\DoctrineStaticMeta\Entity\Embeddable\Traits\Financial\HasMoneyEmbeddableTrait
20
 */
21
class HasMoneyEmbeddableTraitLargeTest extends AbstractLargeTest
22
{
23
    public const WORK_DIR = AbstractTest::VAR_PATH . '/' . self::TEST_TYPE_LARGE . '/HasMoneyEmbeddableTraitTest';
24
25
    private const TEST_ENTITY = self::TEST_ENTITIES_ROOT_NAMESPACE . TestCodeGenerator::TEST_ENTITY_ALL_EMBEDDABLES;
26
    protected static $buildOnce = true;
27
    protected static $built     = false;
28
    private          $entityFqn;
29
30
    public function setup()
31
    {
32
        parent::setUp();
33
        $this->generateTestCode();
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function theEntityCanBeSavedAndLoadedWithCorrectValues(): void
40
    {
41
        $this->copyAndSetEntityFqn();
42
        $entity = $this->createEntity($this->entityFqn);
43
        $entity->update(
44
            new class($this->entityFqn, $entity->getId()) extends AbstractEntityUpdateDto
45
            {
46
                public function getMoneyEmbeddable(): MoneyEmbeddableInterface
47
                {
48
                    return new MoneyEmbeddable(
49
                        new Money(
50
                            100,
51
                            new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)
52
                        )
53
                    );
54
                }
55
            }
56
57
        );
58
59
        $expected = '100';
60
        $loaded   = $this->saveAndReload($entity);
61
        $actual   = $loaded->getMoneyEmbeddable()->getMoney()->getAmount();
62
        self::assertSame($expected, $actual);
63
64
        $loaded->update(
65
            new class($this->entityFqn, $entity->getId()) extends AbstractEntityUpdateDto
66
            {
67
                public function getMoneyEmbeddable(): MoneyEmbeddableInterface
68
                {
69
                    return new MoneyEmbeddable(
70
                        new Money(
71
                            200,
72
                            new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)
73
                        )
74
                    );
75
                }
76
            }
77
78
        );
79
        $reloaded = $this->saveAndReload($loaded);
80
        $expected = '200';
81
        $actual   = $reloaded->getMoneyEmbeddable()->getMoney()->getAmount();
82
        self::assertSame($expected, $actual);
83
    }
84
85
    private function copyAndSetEntityFqn(): void
86
    {
87
        $this->setupCopiedWorkDirAndCreateDatabase();
88
        $this->entityFqn = $this->getCopiedFqn(self::TEST_ENTITY);
89
    }
90
91
    private function saveAndReload(EntityInterface $entity)
92
    {
93
        $this->getEntitySaver()->save($entity);
94
        $repo = $this->getRepositoryFactory()->getRepository(
95
            $entity::getDoctrineStaticMeta()->getReflectionClass()->getName()
96
        );
97
98
        return $repo->findAll()[0];
99
    }
100
101
    /**
102
     * @test
103
     */
104
    public function thereCanBeMultipleOfTheSameArchetypeInAnEntity(): void
105
    {
106
        $priceTraitFqn = $this->getArchetypeEmbeddableGenerator()
107
                              ->setPathToProjectRoot(self::WORK_DIR)
108
                              ->setProjectRootNamespace(self::TEST_PROJECT_ROOT_NAMESPACE)
109
                              ->createFromArchetype(
110
                                  MoneyEmbeddable::class,
111
                                  'PriceEmbeddable'
112
                              );
113
        $this->getEntityEmbeddableSetter()
114
             ->setPathToProjectRoot(self::WORK_DIR)
115
             ->setProjectRootNamespace(self::TEST_PROJECT_ROOT_NAMESPACE)
116
             ->setEntityHasEmbeddable(self::TEST_ENTITY, $priceTraitFqn);
117
        $this->copyAndSetEntityFqn();
118
        $this->recreateDtos();
119
        $entity = $this->createEntity($this->entityFqn);
120
        $entity->update(
121
            new class($this->entityFqn, $entity->getId()) extends AbstractEntityUpdateDto
122
            {
123
                public function getMoneyEmbeddable(): MoneyEmbeddableInterface
124
                {
125
                    return new MoneyEmbeddable(
126
                        new Money(
127
                            100,
128
                            new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)
129
                        )
130
                    );
131
                }
132
            }
133
134
        );
135
        $entity->update(
136
            new class($this->entityFqn, $entity->getId()) extends AbstractEntityUpdateDto
137
            {
138
                public function getPriceEmbeddable()
139
                {
140
                    return new PriceEmbeddable(
141
                        new Money(
142
                            200,
143
                            new Currency(MoneyEmbeddableInterface::DEFAULT_CURRENCY_CODE)
144
                        )
145
                    );
146
                }
147
            }
148
149
        );
150
        $this->getEntitySaver()->save($entity);
151
152
        /**
153
         * @var AbstractEntityRepository $repo
154
         */
155
        $repo     = $this->getRepositoryFactory()->getRepository($this->entityFqn);
156
        $loaded   = $repo->findAll()[0];
157
        $expected = '100';
158
        $actual   = $loaded->getMoneyEmbeddable()->getMoney()->getAmount();
159
        self::assertSame($expected, $actual);
160
        $expected = '200';
161
        $actual   = $loaded->getPriceEmbeddable()->getMoney()->getAmount();
162
        self::assertSame($expected, $actual);
163
    }
164
}
165