コード例 #1
0
 /**
  * (non-PHPdoc)
  * @see MageUC_Console_Task::execute()
  */
 public function execute()
 {
     print '[pdepend] Lancement de PHP Depend : ' . $this->getArgument('to_check') . PHP_EOL;
     $this->_runner = new PHP_Depend_TextUI_Runner();
     $this->_runner->addProcessListener(new PHP_Depend_TextUI_ResultPrinter());
     $this->_runner->addLogger('summary-xml', self::getReportFileName('summary.xml'));
     $this->_runner->addLogger('jdepend-chart', self::getReportFileName('jdepend.svg'));
     $this->_runner->addLogger('jdepend-xml', self::getReportFileName('jdepend.xml'));
     $this->_runner->addLogger('overview-pyramid', self::getReportFileName('pyramid.svg'));
     $arSource = $this->_getFilesToCheck($this->getArgument('to_check'));
     if (!is_array($arSource)) {
         $arSource = array($arSource);
     }
     $this->_runner->setSourceArguments($arSource);
     $configurationFactory = new PHP_Depend_Util_Configuration_Factory();
     $configuration = $configurationFactory->createDefault();
     // Store in config registry
     PHP_Depend_Util_ConfigurationInstance::set($configuration);
     $this->_runner->setConfiguration($configuration);
     $this->_runner->run();
     print '[pdepend] done' . PHP_EOL;
 }
コード例 #2
0
 /**
  * Executes PHP_Depend_TextUI_Runner against PhingFile or a FileSet
  *
  * @return void
  * @throws BuildException
  */
 public function main()
 {
     $autoload = new PHP_Depend_Autoload();
     $autoload->register();
     if (!isset($this->_file) and count($this->_filesets) == 0) {
         throw new BuildException("Missing either a nested fileset or attribute 'file' set");
     }
     if (count($this->_loggers) == 0) {
         throw new BuildException("Missing nested 'logger' element");
     }
     $this->validateLoggers();
     $this->validateAnalyzers();
     $filesToParse = array();
     if ($this->_file instanceof PhingFile) {
         $filesToParse[] = $this->_file->__toString();
     } else {
         // append any files in filesets
         foreach ($this->_filesets as $fs) {
             $files = $fs->getDirectoryScanner($this->project)->getIncludedFiles();
             foreach ($files as $filename) {
                 $f = new PhingFile($fs->getDir($this->project), $filename);
                 $filesToParse[] = $f->getAbsolutePath();
             }
         }
     }
     $this->_runner = new PHP_Depend_TextUI_Runner();
     $this->_runner->addProcessListener(new PHP_Depend_TextUI_ResultPrinter());
     $configurationFactory = new PHP_Depend_Util_Configuration_Factory();
     $configuration = $configurationFactory->createDefault();
     $this->_runner->setConfiguration($configuration);
     $this->_runner->setSourceArguments($filesToParse);
     foreach ($this->_loggers as $logger) {
         // Register logger
         $this->_runner->addLogger($logger->getType(), $logger->getOutfile()->__toString());
     }
     foreach ($this->_analyzers as $analyzer) {
         // Register additional analyzer
         $this->_runner->addOption($analyzer->getType(), $analyzer->getValue());
     }
     // Disable annotation parsing
     if ($this->_withoutAnnotations) {
         $this->_runner->setWithoutAnnotations();
     }
     // Enable bad documentation support
     if ($this->_supportBadDocumentation) {
         $this->_runner->setSupportBadDocumentation();
     }
     // Check for suffix
     if (count($this->_allowedFileExtensions) > 0) {
         $this->_runner->setFileExtensions($this->_allowedFileExtensions);
     }
     // Check for ignore directories
     if (count($this->_excludeDirectories) > 0) {
         $this->_runner->setExcludeDirectories($this->_excludeDirectories);
     }
     // Check for exclude packages
     if (count($this->_excludePackages) > 0) {
         $this->_runner->setExcludePackages($this->_excludePackages);
     }
     // Check for configuration option
     if ($this->_configFile instanceof PhingFile) {
         if (file_exists($this->_configFile->__toString()) === false) {
             throw new BuildException('The configuration file "' . $this->_configFile->__toString() . '" doesn\'t exist.');
         }
         // Load configuration file
         $config = new PHP_Depend_Util_Configuration($this->_configFile->__toString(), null, true);
         // Store in config registry
         PHP_Depend_Util_ConfigurationInstance::set($config);
     }
     if ($this->_debug) {
         require_once 'PHP/Depend/Util/Log.php';
         // Enable debug logging
         PHP_Depend_Util_Log::setSeverity(PHP_Depend_Util_Log::DEBUG);
     }
     $this->_runner->run();
     if ($this->_runner->hasParseErrors() === true) {
         $this->log('Following errors occurred:');
         foreach ($this->_runner->getParseErrors() as $error) {
             $this->log($error);
         }
         if ($this->_haltonerror === true) {
             throw new BuildException('Errors occurred during parse process');
         }
     }
 }
コード例 #3
0
 /**
  * Sets the configuration instance.
  *
  * @param PHP_Depend_Util_Configuration $configuration The config instance.
  *
  * @return void
  */
 public static function set(PHP_Depend_Util_Configuration $configuration = null)
 {
     self::$_configuration = $configuration;
 }
コード例 #4
0
ファイル: ImageConvert.php プロジェクト: rouffj/pdepend
 /**
  * Utility method for svg input files.
  *
  * If the input file has the mime type svg and a configuration file with
  * imageConvert options exists, this method will prepare the input image
  * file.
  *
  * @param string $input The input svg file.
  *
  * @return void
  */
 protected static function prepareSVG($input)
 {
     // Check for a configuration instance
     if (($config = PHP_Depend_Util_ConfigurationInstance::get()) === null) {
         return;
     }
     $svg = file_get_contents($input);
     // Check for font family
     if (isset($config->imageConvert->fontFamily)) {
         // Get font family
         $fontFamily = (string) $config->imageConvert->fontFamily;
         // Replace CSS separators
         $fontReplace = 'font-family:' . strtr($fontFamily, ';:', '  ');
         $fontPattern = '/font-family:\\s*Arial/';
         $svg = preg_replace($fontPattern, $fontReplace, $svg);
     }
     // Check for font size
     if (isset($config->imageConvert->fontSize)) {
         // Get font size
         $fontSize = abs((double) $config->imageConvert->fontSize);
         // Fetch all font-size expressions
         preg_match_all('/font-size:\\s*(\\d+)/', $svg, $fontSizes);
         $fontSizes = array_unique($fontSizes[1]);
         $resize = $fontSize - max($fontSizes);
         foreach ($fontSizes as $fontSize) {
             // Calculate resize value
             $fontReplace = 'font-size:' . ($fontSize + $resize);
             $fontPattern = "/font-size:\\s*{$fontSize}/";
             $svg = preg_replace($fontPattern, $fontReplace, $svg);
         }
     }
     file_put_contents($input, $svg);
 }
コード例 #5
0
ファイル: CommandTest.php プロジェクト: rouffj/pdepend
 /**
  * Tests that the command sets a configuration instance for a specified
  * config file.
  *
  * @return void
  */
 public function testCommandHandlesConfigurationFileCorrect()
 {
     // Sample config file
     $configFile = self::createRunResourceURI('config.xml');
     // Write a dummy config file.
     file_put_contents($configFile, '<?xml version="1.0"?>
          <configuration>
            <cache>
              <driver>memory</driver>
            </cache>
          </configuration>');
     $argv = array('--configuration=' . $configFile, '--dummy-logger=' . self::createRunResourceURI(), __FILE__);
     // Result previous instance
     PHP_Depend_Util_ConfigurationInstance::set(null);
     $this->_executeCommand($argv);
     $config = PHP_Depend_Util_ConfigurationInstance::get();
     self::assertEquals('memory', $config->cache->driver);
 }
コード例 #6
0
ファイル: Command.php プロジェクト: Tjorriemorrie/app
 /**
  * Parses the cli arguments.
  *
  * @return boolean
  */
 protected function handleArguments()
 {
     if (!isset($_SERVER['argv'])) {
         if (false === (bool) ini_get('register_argc_argv')) {
             // @codeCoverageIgnoreStart
             echo 'Please enable register_argc_argv in your php.ini.';
         } else {
             // @codeCoverageIgnoreEnd
             echo 'Unknown error, no $argv array available.';
         }
         echo PHP_EOL, PHP_EOL;
         return false;
     }
     // Get cli arguments
     $argv = $_SERVER['argv'];
     // Remove the pdepend command line file
     array_shift($argv);
     if (count($argv) === 0) {
         return false;
     }
     // Last argument must be a list of source directories
     if (strpos(end($argv), '--') !== 0) {
         $this->_runner->setSourceArguments(explode(',', array_pop($argv)));
     }
     for ($i = 0, $c = count($argv); $i < $c; ++$i) {
         // Is it an ini_set option?
         if ($argv[$i] === '-d' && isset($argv[$i + 1])) {
             if (strpos($argv[++$i], '=') === false) {
                 ini_set($argv[$i], 'on');
             } else {
                 // Split key=value
                 list($key, $value) = explode('=', $argv[$i]);
                 // set ini option
                 ini_set($key, $value);
             }
         } else {
             if (strpos($argv[$i], '=') === false) {
                 $this->_options[$argv[$i]] = true;
             } else {
                 // Split key=value
                 list($key, $value) = explode('=', $argv[$i]);
                 // Set option
                 $this->_options[$key] = $value;
             }
         }
     }
     // Check for suffix option
     if (isset($this->_options['--suffix'])) {
         // Get file extensions
         $extensions = explode(',', $this->_options['--suffix']);
         // Set allowed file extensions
         $this->_runner->setFileExtensions($extensions);
         // Remove from options array
         unset($this->_options['--suffix']);
     }
     // Check for ignore option
     if (isset($this->_options['--ignore'])) {
         // Get exclude directories
         $directories = explode(',', $this->_options['--ignore']);
         // Set exclude directories
         $this->_runner->setExcludeDirectories($directories);
         // Remove from options array
         unset($this->_options['--ignore']);
     }
     // Check for exclude package option
     if (isset($this->_options['--exclude'])) {
         // Get exclude directories
         $packages = explode(',', $this->_options['--exclude']);
         // Set exclude packages
         $this->_runner->setExcludePackages($packages);
         // Remove from options array
         unset($this->_options['--exclude']);
     }
     // Check for the bad documentation option
     if (isset($this->_options['--bad-documentation'])) {
         echo "Option --bad-documentation is ambiguous.", PHP_EOL;
         // Remove from options array
         unset($this->_options['--bad-documentation']);
     }
     // Check for configuration option
     if (isset($this->_options['--configuration'])) {
         // Get config file
         $configFile = $this->_options['--configuration'];
         // Remove option from array
         unset($this->_options['--configuration']);
         // First check config file
         if (file_exists($configFile) === false) {
             // Print error message
             echo 'The configuration file "', $configFile, '" doesn\'t exist.', PHP_EOL, PHP_EOL;
             // Return error
             return false;
         }
         // Load configuration file
         $config = new PHP_Depend_Util_Configuration($configFile, null, true);
         // Store in config registry
         PHP_Depend_Util_ConfigurationInstance::set($config);
     }
     if (isset($this->_options['--debug'])) {
         // Remove option from array
         unset($this->_options['--debug']);
         // Enable debug logging
         PHP_Depend_Util_Log::setSeverity(PHP_Depend_Util_Log::DEBUG);
     }
     return true;
 }
コード例 #7
0
ファイル: ImageConvertTest.php プロジェクト: KingNoosh/Teknik
 /**
  * Tests that the convert util recognizes the imageConvert configuration
  * for the font-size:
  *
  * @return void
  */
 public function testConvertRecognizesFontSizeInConfiguration()
 {
     $settings = new stdClass();
     $settings->imageConvert = new stdClass();
     $settings->imageConvert->fontSize = 14;
     $config = new PHP_Depend_Util_Configuration($settings);
     PHP_Depend_Util_ConfigurationInstance::set($config);
     $input = self::createInputSvg();
     $output = self::createRunResourceURI('pdepend.svg');
     PHP_Depend_Util_ImageConvert::convert($input, $output);
     $svg = file_get_contents($output);
     self::assertEquals(25, substr_count($svg, 'font-size:14px'));
 }
コード例 #8
0
 /**
  * @return PHP_Depend_TextUI_Runner
  */
 private function createLegacyRunner()
 {
     $runner = new PHP_Depend_TextUI_Runner();
     $runner->addProcessListener(new PHP_Depend_TextUI_ResultPrinter());
     if ($this->debug) {
         require_once 'PHP/Depend/Util/Log.php';
         // Enable debug logging
         PHP_Depend_Util_Log::setSeverity(PHP_Depend_Util_Log::DEBUG);
     }
     $configuration = $this->getConfiguration();
     if ($configuration === null) {
         $configurationFactory = new PHP_Depend_Util_Configuration_Factory();
         $configuration = $configurationFactory->createDefault();
     }
     PHP_Depend_Util_ConfigurationInstance::set($configuration);
     $runner->setConfiguration($configuration);
     return $runner;
 }
コード例 #9
0
ファイル: ImageConvertTest.php プロジェクト: noelg/pdepend
 /**
  * Tests that the convert util recognizes the imageConvert configuration
  * for the font-size:
  *
  * @return void
  */
 public function testConvertRecognizesFontSizeInConfiguration()
 {
     $config = new PHP_Depend_Util_Configuration('<?xml version="1.0"?>
     <configuration>
       <imageConvert>
         <fontSize>14</fontSize>
       </imageConvert>
     </configuration>
     ');
     PHP_Depend_Util_ConfigurationInstance::set($config);
     $this->_out = self::createRunResourceURI('pdepend.svg');
     copy(dirname(__FILE__) . '/_input/pyramid.svg', $this->_out);
     $svg = file_get_contents($this->_out);
     preg_match_all('/font-size:\\s*11px/', $svg, $matches);
     $expected11 = count($matches[0]);
     preg_match_all('/font-size:\\s*14px/', $svg, $matches);
     $expected14 = count($matches[0]);
     $this->assertEquals(25, $expected11);
     $this->assertEquals(0, $expected14);
     PHP_Depend_Util_ImageConvert::convert($this->_out, $this->_out);
     $svg = file_get_contents($this->_out);
     preg_match_all('/font-size:\\s*11px/', $svg, $matches);
     $actual11 = count($matches[0]);
     preg_match_all('/font-size:\\s*14px/', $svg, $matches);
     $actual14 = count($matches[0]);
     $this->assertEquals(0, $actual11);
     $this->assertEquals(25, $actual14);
 }
コード例 #10
0
ファイル: Command.php プロジェクト: KingNoosh/Teknik
 /**
  * Parses the cli arguments.
  *
  * @return boolean
  */
 protected function handleArguments()
 {
     if (!isset($_SERVER['argv'])) {
         if (false === (bool) ini_get('register_argc_argv')) {
             // @codeCoverageIgnoreStart
             echo 'Please enable register_argc_argv in your php.ini.';
         } else {
             // @codeCoverageIgnoreEnd
             echo 'Unknown error, no $argv array available.';
         }
         echo PHP_EOL, PHP_EOL;
         return false;
     }
     $argv = $_SERVER['argv'];
     // Remove the pdepend command line file
     array_shift($argv);
     if (count($argv) === 0) {
         return false;
     }
     // Last argument must be a list of source directories
     if (strpos(end($argv), '--') !== 0) {
         $this->runner->setSourceArguments(explode(',', array_pop($argv)));
     }
     for ($i = 0, $c = count($argv); $i < $c; ++$i) {
         // Is it an ini_set option?
         if ($argv[$i] === '-d' && isset($argv[$i + 1])) {
             if (strpos($argv[++$i], '=') === false) {
                 ini_set($argv[$i], 'on');
             } else {
                 list($key, $value) = explode('=', $argv[$i]);
                 ini_set($key, $value);
             }
         } else {
             if (strpos($argv[$i], '=') === false) {
                 $this->options[$argv[$i]] = true;
             } else {
                 list($key, $value) = explode('=', $argv[$i]);
                 $this->options[$key] = $value;
             }
         }
     }
     // Check for suffix option
     if (isset($this->options['--suffix'])) {
         // Get file extensions
         $extensions = explode(',', $this->options['--suffix']);
         // Set allowed file extensions
         $this->runner->setFileExtensions($extensions);
         unset($this->options['--suffix']);
     }
     // Check for ignore option
     if (isset($this->options['--ignore'])) {
         // Get exclude directories
         $directories = explode(',', $this->options['--ignore']);
         // Set exclude directories
         $this->runner->setExcludeDirectories($directories);
         unset($this->options['--ignore']);
     }
     // Check for exclude package option
     if (isset($this->options['--exclude'])) {
         // Get exclude directories
         $packages = explode(',', $this->options['--exclude']);
         // Set exclude packages
         $this->runner->setExcludePackages($packages);
         unset($this->options['--exclude']);
     }
     // Check for the bad documentation option
     if (isset($this->options['--bad-documentation'])) {
         echo "Option --bad-documentation is ambiguous.", PHP_EOL;
         unset($this->options['--bad-documentation']);
     }
     $configurationFactory = new PHP_Depend_Util_Configuration_Factory();
     // Check for configuration option
     if (isset($this->options['--configuration'])) {
         // Get config file
         $configFile = $this->options['--configuration'];
         unset($this->options['--configuration']);
         $configuration = $configurationFactory->create($configFile);
     } else {
         $configuration = $configurationFactory->createDefault();
     }
     // Store in config registry
     PHP_Depend_Util_ConfigurationInstance::set($configuration);
     $this->runner->setConfiguration($configuration);
     if (isset($this->options['--debug'])) {
         unset($this->options['--debug']);
         PHP_Depend_Util_Log::setSeverity(PHP_Depend_Util_Log::DEBUG);
     }
     return true;
 }
コード例 #11
0
ファイル: CommandTest.php プロジェクト: noelg/pdepend
 /**
  * Tests that the command sets a configuration instance for a specified
  * config file.
  *
  * @return void
  * @covers PHP_Depend_TextUI_Command
  * @group pdepend
  * @group pdepend::textui
  * @group unittest
  */
 public function testCommandHandlesConfigurationFileCorrect()
 {
     // Sample config file
     $configFile = self::createRunResourceURI('config.xml');
     // Write a dummy config file.
     file_put_contents($configFile, '<?xml version="1.0"?>
          <configuration>
            <test />
          </configuration>');
     $argv = array('--configuration=' . $configFile, '--dummy-logger=' . self::createRunResourceURI('pdepend.dummy'), __FILE__);
     // Result previous instance
     PHP_Depend_Util_ConfigurationInstance::set(null);
     list($exitCode, $actual) = $this->_executeCommand($argv);
     $test = isset(PHP_Depend_Util_ConfigurationInstance::get()->test);
     $this->assertTrue($test);
 }