Conditions | 1 |
Paths | 1 |
Total Lines | 58 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
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:
If many parameters/temporary variables are present:
1 | <?php |
||
91 | public function testListWithTenantsAndOrganizationOption() |
||
92 | { |
||
93 | $tenant = new Tenant(); |
||
94 | $tenant->setCode('123abc'); |
||
95 | $tenant->setId('1'); |
||
96 | $tenant->setName('Test Tenant'); |
||
97 | $tenant->setCreatedAt(new \DateTime('2017-02-20 15:19:55')); |
||
98 | $organization = new Organization(); |
||
99 | $organization->setCode('123456'); |
||
100 | $organization->setName('Test Organization'); |
||
101 | $organization->addTenant($tenant); |
||
102 | |||
103 | $tenant->setOrganization($organization); |
||
104 | $this->command->setContainer($this->getMockContainer($organization)); |
||
105 | $this->commandTester = new CommandTester($this->command); |
||
106 | $this->commandTester->execute(['command' => $this->command->getName()]); |
||
107 | |||
108 | $result = <<<'EOF' |
||
109 | List of all available tenants: |
||
110 | +----+--------+-------------+------------+---------------------+----------------------------------+ |
||
111 | | Id | Code | Name | Is active? | Created at | Organization | |
||
112 | +----+--------+-------------+------------+---------------------+----------------------------------+ |
||
113 | | 1 | 123abc | Test Tenant | yes | 2017-02-20 15:19:55 | Test Organization (code: 123456) | |
||
114 | +----+--------+-------------+------------+---------------------+----------------------------------+ |
||
115 | EOF; |
||
116 | |||
117 | $this->assertEquals($result, trim($this->commandTester->getDisplay())); |
||
118 | |||
119 | $tenant2 = new Tenant(); |
||
120 | $tenant2->setCode('345def'); |
||
121 | $tenant2->setId('2'); |
||
122 | $tenant2->setName('Test Tenant 2'); |
||
123 | $tenant2->setCreatedAt(new \DateTime('2017-02-20 15:19:55')); |
||
124 | $organization2 = new Organization(); |
||
125 | $organization2->setCode('789012'); |
||
126 | $organization2->setName('Test Organization2'); |
||
127 | $organization2->addTenant($tenant2); |
||
128 | $tenant2->setOrganization($organization2); |
||
129 | |||
130 | $this->command->setContainer($this->getMockContainer($organization2)); |
||
131 | $this->commandTester = new CommandTester($this->command); |
||
132 | $this->commandTester->execute(['command' => $this->command->getName(), '-o' => '123456']); |
||
133 | $result = <<<'EOF' |
||
134 | There are no tenants defined. |
||
135 | EOF; |
||
136 | $this->assertEquals($result, trim($this->commandTester->getDisplay())); |
||
137 | |||
138 | $this->commandTester->execute(['command' => $this->command->getName()]); |
||
139 | $result = <<<'EOF' |
||
140 | List of all available tenants: |
||
141 | +----+--------+---------------+------------+---------------------+-----------------------------------+ |
||
142 | | Id | Code | Name | Is active? | Created at | Organization | |
||
143 | +----+--------+---------------+------------+---------------------+-----------------------------------+ |
||
144 | | 2 | 345def | Test Tenant 2 | yes | 2017-02-20 15:19:55 | Test Organization2 (code: 789012) | |
||
145 | +----+--------+---------------+------------+---------------------+-----------------------------------+ |
||
146 | EOF; |
||
147 | $this->assertEquals($result, trim($this->commandTester->getDisplay())); |
||
148 | } |
||
149 | |||
194 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.