Conditions | 6 |
Paths | 48 |
Total Lines | 72 |
Code Lines | 55 |
Lines | 72 |
Ratio | 100 % |
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 |
||
105 | View Code Duplication | public function testSaveJob() |
|
106 | { |
||
107 | // Make sure a job proper type |
||
108 | $failed = false; |
||
109 | try { |
||
110 | $job = new Job(); |
||
111 | self::$jobManager->save($job); |
||
112 | $failed = true; |
||
113 | } catch (\Exception $exception) { |
||
114 | self::assertTrue(true); |
||
115 | } |
||
116 | self::assertFalse($failed); |
||
117 | |||
118 | $job = new self::$jobClass(self::$worker, false, null); |
||
119 | try { |
||
120 | $job->setPriority(256)->fibonacci(1); |
||
121 | $failed = true; |
||
122 | } catch (\Exception $exception) { |
||
123 | self::assertTrue(true); |
||
124 | } |
||
125 | self::assertFalse($failed); |
||
126 | |||
127 | $job = new self::$jobClass(self::$worker, false, null); |
||
128 | $job->setPriority(100)->fibonacci(1); |
||
129 | self::assertNotNull($job->getId(), 'Job id should be generated'); |
||
130 | |||
131 | $jobInQueue = self::$jobManager->getJob(); |
||
132 | self::assertNotNull($jobInQueue, 'There should be a job.'); |
||
133 | self::$jobManager->saveHistory($jobInQueue); |
||
134 | |||
135 | $job = new self::$jobClass(self::$worker, false, null); |
||
136 | $job->fibonacci(1); |
||
137 | self::assertNotNull($job->getId(), 'Job id should be generated'); |
||
138 | |||
139 | $failed = false; |
||
140 | try { |
||
141 | self::$jobManager->getJob('fibonacci'); |
||
142 | $failed = true; |
||
143 | } catch (\Exception $exception) { |
||
144 | self::assertTrue(true); |
||
145 | } |
||
146 | self::assertFalse($failed); |
||
147 | |||
148 | $failed = false; |
||
149 | try { |
||
150 | self::$jobManager->getJob(null, 'fibonacci'); |
||
151 | $failed = true; |
||
152 | } catch (\Exception $exception) { |
||
153 | self::assertTrue(true); |
||
154 | } |
||
155 | self::assertFalse($failed); |
||
156 | |||
157 | $jobInQueue = self::$jobManager->getJob(); |
||
158 | self::assertNotNull($jobInQueue, 'There should be a job.'); |
||
159 | self::assertEquals( |
||
160 | $job->getId(), |
||
161 | $jobInQueue->getId(), |
||
162 | 'Job id returned by manager should be the same' |
||
163 | ); |
||
164 | |||
165 | $job->setStatus(BaseJob::STATUS_SUCCESS); |
||
166 | $badJob = new Job(); |
||
167 | $failed = false; |
||
168 | try { |
||
169 | self::$jobManager->saveHistory($badJob); |
||
170 | $failed = true; |
||
171 | } catch (\Exception $exception) { |
||
172 | self::assertTrue(true); |
||
173 | } |
||
174 | self::assertFalse($failed); |
||
175 | self::$jobManager->saveHistory($jobInQueue); |
||
176 | } |
||
177 | } |
||
178 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..