Example #1
0
 /**
  * Analyses the architecture.
  *
  * @return bool true if the architecture raised no violation, false if there were violations
  */
 public function analyze(ReportWriterInterface $writer)
 {
     $phpDAConfig = $this->createPhpDAConfig();
     $usageFactory = new UsageFactory();
     $usage = $usageFactory->create();
     $usage->setOptions(['config' => $phpDAConfig]);
     // collect violation report
     $report = new PolicyViolationReport($this->config->getReportUndefined());
     $inspector = new Inspector();
     $inspector->load($this->config->getArchitecture());
     ReferenceValidator::getInstance()->setInspector($inspector);
     ReferenceValidator::getInstance()->setViolationCollector($report);
     $result = $usage->execute();
     // write report
     $writer->write($report);
     return $result;
 }
Example #2
0
 /**
  * Makes sure the architecture file is readable and helps the user if not.
  *
  * @param AIConfig $config
  * @param InputInterface $input
  * @param OutputInterface $output
  *
  * @return bool
  */
 private function isValidArchitectureFile(AIConfig $config, InputInterface $input, OutputInterface $output)
 {
     $arcFile = $config->getArchitecture();
     if (is_readable($arcFile)) {
         return true;
     }
     if (file_exists($arcFile)) {
         // permission error
         $output->writeln(sprintf(CliMessage::ARCHITECTURE_FILE_NOT_READABLE, $arcFile));
     } else {
         // no architecture file present
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion(sprintf(CliMessage::ARCHITECTURE_FILE_ASK_TO_CREATE, $arcFile), false);
         if ($helper->ask($input, $output, $question)) {
             touch($arcFile);
             $output->writeln(sprintf(CliMessage::ARCHITECTURE_FILE_CREATED_EMPTY, $arcFile));
         }
         $output->writeln(CliMessage::ARCHITECTURE_FILE_HOWTO);
     }
     return false;
 }