protected function execute(InputInterface $input, OutputInterface $output) { $validate = new Validate(); $filesystem = new Filesystem(); $project = $input->getArgument('project'); $branch = $input->getOption('branch'); $clone = $input->getOption('clone'); $storage = $input->getOption('storage'); if (!empty($project) && !empty($clone)) { throw new \InvalidArgumentException('Cannot use both the project argument and the --clone option'); } if (!empty($project)) { $cloneUrl = sprintf('https://github.com/%s.git', $project); } elseif (!empty($clone)) { $cloneUrl = $clone; } else { throw new \RuntimeException('Must use the project argument or --clone option'); } $filesystem->mkdir($storage); $storageDir = realpath($validate->directory($storage)); $process = new Process(sprintf('git clone --depth 1 --branch %s %s', $branch, $cloneUrl), $storageDir); $this->execute->mustRun($process); $dumper = new EnvDumper(); $dumper->dump(['EXTRA_PLUGINS_DIR' => $storageDir], $this->envFile); }
protected function initialize(InputInterface $input, OutputInterface $output) { if (!$this->plugin) { $validate = new Validate(); $pluginDir = realpath($validate->directory($input->getArgument('plugin'))); $this->plugin = new MoodlePlugin($pluginDir); } }
/** * Initialize the moodle property based on input if necessary. * * @param InputInterface $input */ protected function initializeMoodle(InputInterface $input) { if (!$this->moodle) { $validate = new Validate(); $moodleDir = realpath($validate->directory($input->getOption('moodle'))); $this->moodle = new Moodle($moodleDir); } }
protected function execute(InputInterface $input, OutputInterface $output) { $this->outputHeading($output, 'PHP Mess Detector on %s'); $files = $this->plugin->getFiles(Finder::create()->name('*.php')); if (count($files) === 0) { return $this->outputSkip($output); } $validate = new Validate(); $rules = realpath($validate->filePath($input->getOption('rules'))); $renderer = new MessDetectorRenderer($output, $this->moodle->directory); $renderer->setWriter(new StreamWriter(STDOUT)); $ruleSetFactory = new RuleSetFactory(); $ruleSetFactory->setMinimumPriority(5); $messDetector = new PHPMD(); $messDetector->processFiles(implode(',', $files), $rules, [$renderer], $ruleSetFactory); }
/** * Create a new installer factory from input options. * * @param InputInterface $input * * @return InstallerFactory */ public function initializeInstallerFactory(InputInterface $input) { $validate = new Validate(); $resolver = new DatabaseResolver(); $pluginDir = realpath($validate->directory($input->getOption('plugin'))); $pluginsDir = $input->getOption('extra-plugins'); if (!empty($pluginsDir)) { $pluginsDir = realpath($validate->directory($pluginsDir)); } $dumper = new ConfigDumper(); $dumper->addSection('filter', 'notPaths', $this->csvToArray($input->getOption('not-paths'))); $dumper->addSection('filter', 'notNames', $this->csvToArray($input->getOption('not-names'))); $factory = new InstallerFactory(); $factory->moodle = new Moodle($input->getOption('moodle')); $factory->plugin = new MoodlePlugin($pluginDir); $factory->execute = $this->execute; $factory->branch = $validate->moodleBranch($input->getOption('branch')); $factory->dataDir = $input->getOption('data'); $factory->dumper = $dumper; $factory->pluginsDir = $pluginsDir; $factory->database = $resolver->resolveDatabase($input->getOption('db-type'), $input->getOption('db-name'), $input->getOption('db-user'), $input->getOption('db-pass'), $input->getOption('db-host')); return $factory; }
/** * @param string $branch * * @dataProvider invalidMoodleBranchProvider * @expectedException \InvalidArgumentException */ public function testMoodleBranchInvalid($branch) { $validate = new Validate(); $this->assertEquals($branch, $validate->moodleBranch($branch), "Validate that {$branch} is NOT valid"); }
/** * Converts a path to an absolute path. * * @param string $path * * @return string */ public function expandPath($path) { $validate = new Validate(); return realpath($validate->directory($path)); }