Conditions | 10 |
Paths | 34 |
Total Lines | 52 |
Code Lines | 34 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 0 | Features | 1 |
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 |
||
41 | public function applyAction() |
||
42 | { |
||
43 | $console = $this->getServiceLocator()->get('console'); |
||
44 | if (!$console instanceof Console) { |
||
45 | throw new RuntimeException('Cannot obtain console adapter. Are we running in a console?'); |
||
46 | } |
||
47 | |||
48 | $fixturePath = $this->getFixtureFolder(); |
||
49 | if (!is_dir($fixturePath)) { |
||
50 | mkdir($fixturePath, 0777); |
||
51 | $console->writeLine('Don\'t exists folder of fixtures!', Color::RED); |
||
52 | return; |
||
53 | } |
||
54 | |||
55 | $adapter = $this->getServiceLocator()->get('Zend\Db\Adapter\Adapter'); |
||
56 | $model = new Fixture($adapter); |
||
|
|||
57 | $request = $this->getRequest(); |
||
58 | $fixtureName = $request->getParam('name', 'all'); |
||
59 | |||
60 | if ($fixtureName == 'all') { |
||
61 | $fixtureFiles = scandir($fixturePath); |
||
62 | unset($fixtureFiles[0]); |
||
63 | unset($fixtureFiles[1]); |
||
64 | } else { |
||
65 | $fixtureFiles = array($fixtureName . '.php'); |
||
66 | } |
||
67 | |||
68 | foreach ($fixtureFiles as $fixtureFile) { |
||
69 | $fixture = include $fixturePath . $fixtureFile; |
||
70 | |||
71 | foreach ($fixture as $tableName => $rows) { |
||
72 | $console->writeLine( |
||
73 | 'Will apply fixture of the table "'.$tableName.'" from file: '.$fixtureFile, |
||
74 | Color::GREEN |
||
75 | ); |
||
76 | $values = isset($rows['values']) ? $rows['values'] : $rows; |
||
77 | |||
78 | foreach ($values as $rowNumber => $row) { |
||
79 | try { |
||
80 | $row = isset($rows['keys']) ? array_combine($rows['keys'], $row) : $row; |
||
81 | |||
82 | $model->insert($tableName, $row); |
||
83 | } catch (\Exception $err) { |
||
84 | $console->writeLine(' - error in row: ' . $rowNumber, Color::RED); |
||
85 | $console->writeLine($err->getMessage(), Color::RED); |
||
86 | } |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | $console->writeLine('Fixture files applied', Color::GREEN); |
||
92 | } |
||
93 | |||
108 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: