| Conditions | 4 |
| Paths | 4 |
| Total Lines | 52 |
| Code Lines | 30 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 23 | public function up(Schema $schema): void |
||
| 24 | { |
||
| 25 | $kernel = $this->container->get('kernel'); |
||
|
|
|||
| 26 | $baseTranslationPath = $kernel->getProjectDir().'/var/translations/messages.'; |
||
| 27 | |||
| 28 | $fs = new Filesystem(); |
||
| 29 | |||
| 30 | $subLanguages = $this->connection |
||
| 31 | ->executeQuery("SELECT id, isocode, parent_id FROM language WHERE parent_id IS NOT NULL") |
||
| 32 | ->fetchAllAssociative() |
||
| 33 | ; |
||
| 34 | |||
| 35 | /** @var array $subLanguage */ |
||
| 36 | foreach ($subLanguages as $subLanguage) { |
||
| 37 | |||
| 38 | $parentIsoCode = $this->connection |
||
| 39 | ->executeQuery('SELECT isocode FROM language WHERE id = ?', [$subLanguage['parent_id']]) |
||
| 40 | ->fetchOne() |
||
| 41 | ; |
||
| 42 | |||
| 43 | $newIsoCode = sprintf( |
||
| 44 | '%s_%d', |
||
| 45 | explode('_', $parentIsoCode)[0], |
||
| 46 | $subLanguage['id'] |
||
| 47 | ); |
||
| 48 | |||
| 49 | $params = [ |
||
| 50 | 'new_iso' => $newIsoCode, |
||
| 51 | 'old_iso' => $subLanguage['isocode'], |
||
| 52 | ]; |
||
| 53 | |||
| 54 | if ($params['new_iso'] === $params['old_iso']) { |
||
| 55 | continue; |
||
| 56 | } |
||
| 57 | |||
| 58 | $this->addSql( |
||
| 59 | 'UPDATE language SET isocode = :new_iso WHERE id = :id', |
||
| 60 | [ |
||
| 61 | 'new_iso' => $newIsoCode, |
||
| 62 | 'id' => $subLanguage['id'], |
||
| 63 | ] |
||
| 64 | ); |
||
| 65 | |||
| 66 | $this->addSql('UPDATE user SET locale = :new_iso WHERE locale = :old_iso', $params); |
||
| 67 | $this->addSql('UPDATE course SET course_language = :new_iso WHERE course_language = :old_iso', $params); |
||
| 68 | $this->addSql("UPDATE settings SET selected_value = :new_iso WHERE variable = 'platform_language' AND selected_value = :old_iso", $params); |
||
| 69 | |||
| 70 | $oldPoFile = $baseTranslationPath.$params['old_iso'].'.po'; |
||
| 71 | $newPoFile = $baseTranslationPath.$params['new_iso'].'.po'; |
||
| 72 | |||
| 73 | if ($fs->exists($oldPoFile)) { |
||
| 74 | $fs->rename($oldPoFile, $newPoFile); |
||
| 75 | } |
||
| 79 |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.