protected function execute(InputInterface $input, OutputInterface $output) { $dir = $input->getArgument('dir'); if (extension_loaded('xdebug')) { $output->writeln('<error>It is highly recommended to disable the XDebug extension before invoking this command.</error>'); } $output->writeln('Scanning directory <info>' . $dir . '</info>'); $files = FileCollection::createFromDirectory($dir, '*.php', array('paths' => $input->getOption('include-pattern'), 'excluded_paths' => $input->getOption('exclude-pattern'))); $output->writeln(sprintf('found <info>%d files</info>', count($files))); if (count($files) > 100) { $output->writeln('<comment>Caution: You are trying to scan a lot of files; this might be slow. For bigger libraries, consider setting up a dedicated platform or using scrutinizer-ci.com.</comment>'); } $output->writeln('Starting analysis...'); $analyzer = Analyzer::create(TestUtils::createTestEntityManager()); $analyzer->setLogger(new OutputLogger($output, $input->getOption('verbose'))); $analyzer->analyze($files); if ($input->getOption('filter-pattern')) { $files = $files->filter($input->getOption('filter-pattern')); } switch ($input->getOption('format')) { case 'plain': $formatter = new OutputFormatter\TextFormatter(); break; default: $formatter = new OutputFormatter\SerializerFormatter($input->getOption('output-file'), $input->getOption('format')); break; } $formatter->write($output, $files); }
protected function getEntityManager() { if (!isset($_SERVER['MYSQL_USER']) || !isset($_SERVER['MYSQL_HOST']) || !isset($_SERVER['MYSQL_PASSWORD']) || !isset($_SERVER['MYSQL_DATABASE'])) { $this->markTestSkipped('You need to configure a MySQL database, see phpunit.dist.xml'); } return TestUtils::createMysqlTestEntityManager($_SERVER['MYSQL_USER'], $_SERVER['MYSQL_PASSWORD'], $_SERVER['MYSQL_DATABASE'], $_SERVER['MYSQL_HOST']); }
protected function setUp() { $this->em = TestUtils::createTestEntityManager(); $this->analyzer = \Scrutinizer\PhpAnalyzer\Analyzer::create($this->em); $defaultConfig = array(); foreach ($this->analyzer->getPassConfig()->getConfigurablePasses() as $pass) { $node = $pass->getConfiguration()->buildTree(); assert($node instanceof ArrayNode); if (array_key_exists('enabled', $node->getChildren())) { $defaultConfig[$node->getName()]['enabled'] = true; } } // Some manual changes. $defaultConfig['suspicious_code']['overriding_parameter'] = true; $defaultConfig['verify_php_doc_comments'] = array_merge($defaultConfig['verify_php_doc_comments'], array('suggest_more_specific_types' => true, 'ask_for_return_if_not_inferrable' => true, 'ask_for_param_type_annotation' => true)); $this->analyzer->setConfigurationValues($defaultConfig); }
protected function execute(InputInterface $input, OutputInterface $output) { if (is_file($dbFile = __DIR__ . '/../../../../res/test_database.sqlite')) { unlink($dbFile); } $em = TestUtils::createTestEntityManager(); $tool = new SchemaTool($em); $tool->createSchema($em->getMetadataFactory()->getAllMetadata()); $analyzer = Analyzer::create($em, PassConfig::createForTypeScanning()); $packageScanner = new PackageScanner($analyzer); $packageScanner->setLogger(new OutputLogger($output, $input->getOption('verbose'))); $package = new Package('PHP'); $packageVersion = $package->createVersion('5.3'); $packageVersion->setUuid(uniqid(mt_rand(), true)); $packageScanner->scanDirectory($packageVersion, __DIR__ . '/../../../../res/php-5.3-core-api'); $output->writeln('Files scanned.'); $output->write('Persisting results... '); $em->persist($package); $em->flush(); $output->writeln('Done'); }
protected function getEntityManager() { return TestUtils::createTestEntityManager(true); }
protected function setUp() { $this->em = TestUtils::createTestEntityManager(); }
protected function getAnalyzer() { return Analyzer::create(TestUtils::createTestEntityManager(), PassConfig::createForTypeScanning()); }
protected function setUp() { $this->typeRegistry = new TypeRegistry(); $this->em = TestUtils::createTestEntityManager(true); $con = $this->em->getConnection(); $paramPersister = new ParameterPersister($con); $callSitePersister = new CallSitePersister($con, new ArgumentPersister($con)); $this->persister = new PackageVersionPersister($con, new MethodContainerPersister($con, new MethodPersister($con, $paramPersister, $callSitePersister), new PropertyPersister($con), new ConstantPersister($con)), new FunctionPersister($con, $paramPersister, $callSitePersister), new GlobalConstantPersister($con)); $package = new Package('foo'); $this->packageVersion = $package->createVersion('1.0'); $this->em->persist($package); $this->em->flush(); }
protected function setUp() { if (!isset($_SERVER['MYSQL_USER']) || !isset($_SERVER['MYSQL_HOST']) || !isset($_SERVER['MYSQL_PASSWORD']) || !isset($_SERVER['MYSQL_DATABASE'])) { $this->markTestSkipped('You need to configure a MySQL database, see phpunit.dist.xml'); } $this->em = TestUtils::createMysqlTestEntityManager($_SERVER['MYSQL_USER'], $_SERVER['MYSQL_PASSWORD'], $_SERVER['MYSQL_DATABASE'], $_SERVER['MYSQL_HOST']); $this->repo = $this->em->getRepository('Scrutinizer\\PhpAnalyzer\\Model\\Package'); $this->typeProvider = new EntityTypeProvider($this->em); $this->typeRegistry = new TypeRegistry($this->typeProvider); $this->package = new Package('foo'); $this->packageVersion = $this->package->createVersion('1.0'); $this->packageVersion->setAttribute('dir', __DIR__); $this->em->persist($this->package); $this->otherPackage = new Package('bar'); $this->otherPackageVersion = $this->otherPackage->createVersion('0.1'); $this->otherPackageVersion->setAttribute('dir', __DIR__); $this->em->persist($this->otherPackage); $this->em->flush(); }
protected function getAnalyzer() { return Analyzer::create(TestUtils::createTestEntityManager(), $this->getPassConfig()); }