console-helpers /
code-insight
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | /** |
||
| 3 | * This file is part of the Code-Insight library. |
||
| 4 | * For the full copyright and license information, please view |
||
| 5 | * the LICENSE file that was distributed with this source code. |
||
| 6 | * |
||
| 7 | * @copyright Alexander Obuhovich <[email protected]> |
||
| 8 | * @link https://github.com/console-helpers/code-insight |
||
| 9 | */ |
||
| 10 | |||
| 11 | namespace ConsoleHelpers\CodeInsight\Command; |
||
| 12 | |||
| 13 | |||
| 14 | use ConsoleHelpers\CodeInsight\KnowledgeBase\KnowledgeBaseFactory; |
||
| 15 | use Symfony\Component\Console\Input\InputArgument; |
||
| 16 | use Symfony\Component\Console\Input\InputInterface; |
||
| 17 | use Symfony\Component\Console\Output\OutputInterface; |
||
| 18 | |||
| 19 | class BackwardsCompatibilityCommand extends AbstractCommand |
||
| 20 | { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * Knowledge base factory. |
||
| 24 | * |
||
| 25 | * @var KnowledgeBaseFactory |
||
| 26 | */ |
||
| 27 | private $_knowledgeBaseFactory; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * {@inheritdoc} |
||
| 31 | */ |
||
| 32 | protected function configure() |
||
| 33 | { |
||
| 34 | $this |
||
| 35 | ->setName('backwards-compatibility') |
||
| 36 | ->setAliases(array('bc')) |
||
| 37 | ->setDescription('Detects backwards compatibility breaks between 2 project versions') |
||
| 38 | ->addArgument( |
||
| 39 | 'source-project-path', |
||
| 40 | InputArgument::REQUIRED, |
||
| 41 | 'Path to source project root folder (where <comment>.code-insight.json</comment> is located)' |
||
| 42 | ) |
||
| 43 | ->addArgument( |
||
| 44 | 'target-project-path', |
||
| 45 | InputArgument::OPTIONAL, |
||
| 46 | 'Path to target project root folder (where <comment>.code-insight.json</comment> is located)', |
||
| 47 | '.' |
||
| 48 | ); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Prepare dependencies. |
||
| 53 | * |
||
| 54 | * @return void |
||
| 55 | */ |
||
| 56 | protected function prepareDependencies() |
||
| 57 | { |
||
| 58 | parent::prepareDependencies(); |
||
| 59 | |||
| 60 | $container = $this->getContainer(); |
||
| 61 | |||
| 62 | $this->_knowledgeBaseFactory = $container['knowledge_base_factory']; |
||
| 63 | } |
||
| 64 | |||
| 65 | /** |
||
| 66 | * {@inheritdoc} |
||
| 67 | */ |
||
| 68 | protected function execute(InputInterface $input, OutputInterface $output) |
||
| 69 | { |
||
| 70 | $source_knowledge_base = $this->_knowledgeBaseFactory->getKnowledgeBase( |
||
| 71 | $this->getPath('source-project-path'), |
||
| 72 | $this->io |
||
| 73 | ); |
||
| 74 | $target_knowledge_base = $this->_knowledgeBaseFactory->getKnowledgeBase( |
||
| 75 | $this->getPath('target-project-path'), |
||
| 76 | $this->io |
||
| 77 | ); |
||
| 78 | |||
| 79 | $bc_breaks = $target_knowledge_base->getBackwardsCompatibilityBreaks($source_knowledge_base->getDatabase()); |
||
| 80 | |||
| 81 | if ( !$bc_breaks ) { |
||
|
1 ignored issue
–
show
|
|||
| 82 | $this->io->writeln('No backwards compatibility breaks detected.'); |
||
| 83 | |||
| 84 | return; |
||
| 85 | } |
||
| 86 | |||
| 87 | $this->io->writeln('Backward compatibility breaks:'); |
||
| 88 | |||
| 89 | foreach ( $bc_breaks as $bc_break => $incidents ) { |
||
| 90 | $this->io->writeln('<fg=red>=== ' . $bc_break . ' ===</>'); |
||
| 91 | |||
| 92 | foreach ( $incidents as $incident ) { |
||
| 93 | $incident = implode(PHP_EOL . ' ', explode(PHP_EOL, $incident)); |
||
| 94 | |||
| 95 | $this->io->writeln(' * ' . $incident); |
||
| 96 | } |
||
| 97 | |||
| 98 | $this->io->writeln(''); |
||
| 99 | } |
||
| 100 | } |
||
| 101 | |||
| 102 | } |
||
| 103 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.