/**
  * Executes a command via CLI
  *
  * @param Console\Input\InputInterface $input
  * @param Console\Output\OutputInterface $output
  *
  * @return int|null|void
  */
 protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output)
 {
     $tempFolder = $input->getOption('temp-folder');
     $destinationFolder = $input->getOption('src-destination');
     if (empty($destinationFolder)) {
         $destinationFolder = realpath(__DIR__ . '/../../../../');
     }
     if (!is_writable($destinationFolder)) {
         $output->writeln('Chash update failed: the "' . $destinationFolder . '" directory used to update the Chash file could not be written');
         return 0;
     }
     if (!is_writable($tempFolder)) {
         $output->writeln('Chash update failed: the "' . $tempFolder . '" directory used to download the temp file could not be written');
         return 0;
     }
     //$protocol = extension_loaded('openssl') ? 'https' : 'http';
     $protocol = 'http';
     $rfs = new RemoteFilesystem(new NullIO());
     // Chamilo version
     //$latest = trim($rfs->getContents('version.chamilo.org', $protocol . '://version.chamilo.org/version.php', false));
     //https://github.com/chamilo/chash/archive/master.zip
     $tempFile = $tempFolder . '/chash-master.zip';
     $rfs->copy('github.com', 'https://github.com/chamilo/chash/archive/master.zip', $tempFile);
     if (!file_exists($tempFile)) {
         $output->writeln('Chash update failed: the "' . $tempFile . '" file could not be written');
         return 0;
     }
     $folderPath = $tempFolder . '/chash';
     if (!is_dir($folderPath)) {
         mkdir($folderPath);
     }
     $zippy = Zippy::load();
     $archive = $zippy->open($tempFile);
     try {
         $archive->extract($folderPath);
     } catch (\Alchemy\Zippy\Exception\RunTimeException $e) {
         $output->writeln("<comment>Chash update failed during unzip.");
         $output->writeln($e->getMessage());
         return 0;
     }
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $fs->mirror($folderPath . '/chash-master', $destinationFolder, null, array('override' => true));
     $output->writeln('Copying ' . $folderPath . '/chash-master to ' . $destinationFolder);
 }
Ejemplo n.º 2
0
 private function render()
 {
     $this->prepareOutputDIrectory();
     $files = $this->score->getClasses();
     $methods = $this->score->getMethods() ?: array();
     $branches = $this->score->getBranches() ?: array();
     $paths = $this->score->getPaths() ?: array();
     $classes = array_unique(array_merge(array_keys($methods), array_keys($branches), array_keys($paths)));
     $coverageModel = new model\coverage();
     $coverageScore = new score\coverage();
     foreach ($classes as $className) {
         $classMethods = array_unique(array_merge(array_keys(isset($methods[$className]) ? $methods[$className] : array()), array_keys(isset($branches[$className]) ? $branches[$className] : array()), array_keys(isset($paths[$className]) ? $paths[$className] : array())));
         $classLines = file($files[$className]);
         $classModel = new model\coverage\klass($className);
         $classCoverage = new score\coverage();
         foreach ($classLines as $number => $line) {
             $classModel->addLine($number + 1, $line);
         }
         foreach ($classMethods as $methodName) {
             $methodLines = isset($methods[$className][$methodName]) ? $methods[$className][$methodName] : array();
             $methodBranches = isset($branches[$className][$methodName]) ? $branches[$className][$methodName] : array();
             $methodPaths = isset($paths[$className][$methodName]) ? $paths[$className][$methodName] : array();
             $reflectedMethod = new \reflectionMethod($className, $methodName);
             $startLineNumber = $reflectedMethod->getStartLine();
             $methodModel = new model\coverage\method($methodName, $methodBranches, $methodPaths);
             $methodCoverage = new score\coverage();
             $classModel->addLine($startLineNumber, rtrim($classLines[$startLineNumber - 1]), null, $methodName);
             $methodCoverage->linesAreAvailable($methodLines);
             $methodCoverage->pathsAreAvailable($methodPaths);
             foreach ($methodLines as $number => $hit) {
                 $classModel->addLine($number, rtrim($classLines[$number - 1]), $hit);
             }
             foreach ($methodBranches as $branch) {
                 $methodCoverage->branchIsAvailable($branch);
             }
             $methodCoverage->addToModel($methodModel);
             $methodModel->addToModel($classModel);
             $classCoverage = $classCoverage->merge($methodCoverage);
         }
         $classCoverage->addToModel($classModel);
         $classModel->addToModel($coverageModel);
         $this->classCodeCoverageIsAvailable($className, $classModel);
         $coverageScore = $coverageScore->merge($classCoverage);
     }
     $coverageScore->addToModel($coverageModel);
     $this->codeCoverageIsAvailable($coverageModel);
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $fs->mirror(__DIR__ . '/../../resources/html/assets', $this->outputDirectory . DIRECTORY_SEPARATOR . 'assets');
     $fs->mirror(__DIR__ . '/../../resources/html/fonts', $this->outputDirectory . DIRECTORY_SEPARATOR . 'fonts');
 }
Ejemplo n.º 3
0
 /**
  * Copies a directory. Uses Symfony's mirror() under the cover.
  *
  * @see \Symfony\Component\Filesystem\Filesystem::mirror()
  *
  * @param string $origin
  * @param string $target
  */
 public static function copyDir($origin, $target)
 {
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $fs->mirror($origin, $target);
 }
Ejemplo n.º 4
0
 /**
  * Moves files into another folder
  *
  * @param type $sourcePath
  * @param type $targetPath
  * @return type
  */
 protected function moveFilesIntoTargetFolder($sourcePath, $targetPath)
 {
     $filesystem = new \Symfony\Component\Filesystem\Filesystem();
     $filesystem->mirror($sourcePath, $targetPath);
     $finder = new \Symfony\Component\Finder\Finder();
     $iterator = $finder->files()->ignoreUnreadableDirs(true)->followLinks()->in($sourcePath);
     $sFiles = [];
     foreach ($iterator as $file) {
         $relativePathFile = str_replace($sourcePath, '', $file->getRealPath());
         if (!file_exists($targetPath . $relativePathFile)) {
             $sFiles[$relativePathFile] = $targetPath . $relativePathFile;
         }
     }
     return $this->setArrayToJson($sFiles);
 }
Ejemplo n.º 5
0
 public function testDate()
 {
     $fs = new \Symfony\Component\Filesystem\Filesystem();
     $fs->mirror(__DIR__ . '/fixtures/', __DIR__ . '/temp/');
     $fs->touch(__DIR__ . '/temp/css/reset.css', 1339690408);
     $fs->touch(__DIR__ . '/temp/css/style.css', 1339690408);
     $filesystem = new Filesystem(new Local(__DIR__ . '/temp'));
     $finder = new Finder($filesystem);
     $this->assertSame($finder, $finder->files()->date('until last month'));
     $this->assertIterator(['css/reset.css', 'css/style.css'], $finder->in('/')->getIterator());
 }