Conditions | 10 |
Paths | 12 |
Total Lines | 51 |
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 |
||
64 | protected function execute(InputInterface $input, OutputInterface $output): int { |
||
65 | $schema = new SchemaWrapper($this->connection); |
||
66 | $isSqlite = $this->connection->getDatabasePlatform() instanceof SqlitePlatform; |
||
|
|||
67 | $updates = []; |
||
68 | |||
69 | $tables = $this->getColumnsByTable(); |
||
70 | foreach ($tables as $tableName => $columns) { |
||
71 | if (!$schema->hasTable($tableName)) { |
||
72 | continue; |
||
73 | } |
||
74 | |||
75 | $table = $schema->getTable($tableName); |
||
76 | |||
77 | foreach ($columns as $columnName) { |
||
78 | $column = $table->getColumn($columnName); |
||
79 | $isAutoIncrement = $column->getAutoincrement(); |
||
80 | $isAutoIncrementOnSqlite = $isSqlite && $isAutoIncrement; |
||
81 | if ($column->getType()->getName() !== Types::BIGINT && !$isAutoIncrementOnSqlite) { |
||
82 | $column->setType(Type::getType(Types::BIGINT)); |
||
83 | $column->setOptions(['length' => 20]); |
||
84 | $column->setUnsigned(true); |
||
85 | |||
86 | $updates[] = '* ' . $tableName . '.' . $columnName; |
||
87 | } |
||
88 | } |
||
89 | } |
||
90 | |||
91 | if (empty($updates)) { |
||
92 | $output->writeln('<info>All tables already up to date!</info>'); |
||
93 | return 0; |
||
94 | } |
||
95 | |||
96 | $output->writeln('<comment>Following columns will be updated:</comment>'); |
||
97 | $output->writeln(''); |
||
98 | $output->writeln($updates); |
||
99 | $output->writeln(''); |
||
100 | $output->writeln('<comment>This can take up to hours, depending on the number of Collabora WOPI tokens in your instance!</comment>'); |
||
101 | |||
102 | if ($input->isInteractive()) { |
||
103 | $helper = $this->getHelper('question'); |
||
104 | $question = new ConfirmationQuestion('Continue with the conversion (y/n)? [n] ', false); |
||
105 | |||
106 | if (!$helper->ask($input, $output, $question)) { |
||
107 | return 1; |
||
108 | } |
||
109 | } |
||
110 | |||
111 | $this->connection->migrateToSchema($schema->getWrappedSchema()); |
||
112 | |||
113 | return 0; |
||
114 | } |
||
115 | } |
||
116 |
This error could be the result of:
1. Missing dependencies
PHP Analyzer uses your
composer.json
file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects thecomposer.json
to be in the root folder of your repository.Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the
require
orrequire-dev
section?2. Missing use statement
PHP does not complain about undefined classes in
ìnstanceof
checks. For example, the following PHP code will work perfectly fine:If you have not tested against this specific condition, such errors might go unnoticed.