当前位置: 首页>>代码示例>>PHP>>正文


PHP analysis\Inspector类代码示例

本文整理汇总了PHP中lithium\analysis\Inspector的典型用法代码示例。如果您正苦于以下问题:PHP Inspector类的具体用法?PHP Inspector怎么用?PHP Inspector使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Inspector类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: analyze

 /**
  * Analyzes code coverage results collected from XDebug, and performs coverage density analysis.
  *
  * @param object $report The report instance running this filter and aggregating results
  * @param array $classes A list of classes to analyze coverage on. By default, gets all
  *              defined subclasses of lithium\test\Unit which are currently in memory.
  * @return array|void Returns an array indexed by file and line, showing the number of
  *                    instances each line was called.
  */
 public static function analyze($report, array $classes = array())
 {
     $data = static::collect($report->results['filters'][__CLASS__]);
     $classes = $classes ?: array_filter(get_declared_classes(), function ($class) use($data) {
         $unit = 'lithium\\test\\Unit';
         return !is_subclass_of($class, $unit) || array_key_exists($class, $data);
     });
     $classes = array_values(array_intersect((array) $classes, array_keys($data)));
     $densities = $result = array();
     foreach ($classes as $class) {
         $classMap = array($class => Libraries::path($class));
         $densities += static::_density($data[$class], $classMap);
     }
     $executableLines = array();
     if (!empty($classes)) {
         $executableLines = array_combine($classes, array_map(function ($cls) {
             return Inspector::executable($cls, array('public' => false));
         }, $classes));
     }
     foreach ($densities as $class => $density) {
         $executable = $executableLines[$class];
         $covered = array_intersect(array_keys($density), $executable);
         $uncovered = array_diff($executable, $covered);
         $percentage = round(count($covered) / (count($executable) ?: 1), 4) * 100;
         $result[$class] = compact('class', 'executable', 'covered', 'uncovered', 'percentage');
     }
     $result = static::collectLines($result);
     return $result;
 }
开发者ID:EHER,项目名称:chegamos,代码行数:38,代码来源:Coverage.php

示例2: _initSteps

 /**
  * Creates step list for this exercise.
  * 
  * @return void
  */
 protected function _initSteps()
 {
     $methods = Inspector::methods($this)->to('array');
     foreach ($methods as $method) {
         if (substr($method['name'], 0, strlen($this->_methodPrefix)) === $this->_methodPrefix) {
             $this->_steps[] = $method['name'];
         }
     }
 }
开发者ID:raisinbread,项目名称:li3_exercises,代码行数:14,代码来源:Exercise.php

示例3: explainExplainMethods

 /**
  * "Explain" methods step.
  *
  * @return void
  */
 public function explainExplainMethods()
 {
     $this->header("The Explain Methods");
     $this->out("The next step is to create your first `explain` method. When an exercise is run, each user-defined method that begins with 'explain' is run in the order it was defined.\n");
     $this->out("Let's start by defining a new method called `explainIntro`.");
     $this->halt();
     $methods = \lithium\analysis\Inspector::methods('\\li3_exercises\\extensions\\exercises\\Blog', 'extents');
     $this->assertTrue(isset($methods['explainIntro']), "Hmmm. I can't seem to find a method defined on your new Blog class named '{:purple}explainIntro{:end}'. {:error}Make sure it has public visibility!{:end}");
 }
开发者ID:raisinbread,项目名称:li3_exercises,代码行数:14,代码来源:Example.php

示例4: _methods

 /**
  * Get the methods to test.
  *
  * @param string $request
  * @return string
  */
 protected function _methods($request)
 {
     $use = $this->_use($request);
     $path = Libraries::path($use);
     if (!file_exists($path)) {
         return "";
     }
     $methods = (array) Inspector::methods($use, 'extents');
     $testMethods = array();
     foreach (array_keys($methods) as $method) {
         $testMethods[] = "\tpublic function test" . ucwords($method) . "() {}";
     }
     return join("\n", $testMethods);
 }
开发者ID:WarToaster,项目名称:HangOn,代码行数:20,代码来源:Test.php

示例5: apply

 /**
  * Takes an instance of an object (usually a Collection object) containing test
  * instances. Introspects the test subject classes to extract cyclomatic complexity data.
  *
  * @param object $report Instance of Report which is calling apply.
  * @param array $tests The test to apply this filter on
  * @param array $options Not used.
  * @return object|void Returns the instance of `$tests`.
  */
 public static function apply($report, $tests, array $options = array())
 {
     $results = array();
     foreach ($tests->invoke('subject') as $class) {
         $results[$class] = array();
         if (!($methods = Inspector::methods($class, 'ranges', array('public' => false)))) {
             continue;
         }
         foreach ($methods as $method => $lines) {
             $lines = Inspector::lines($class, $lines);
             $branches = Parser::tokenize(join("\n", (array) $lines), array('include' => static::$_include));
             $results[$class][$method] = count($branches) + 1;
             $report->collect(__CLASS__, $results);
         }
     }
     return $tests;
 }
开发者ID:rudiedirkx,项目名称:MyLithium,代码行数:26,代码来源:Complexity.php

示例6: _affected

 /**
  * Returns all classes directly depending on a given class.
  *
  * @param string $dependency The class name to use as a dependency.
  * @param string $exclude Regex path exclusion filter.
  * @return array Classes having a direct dependency on `$dependency`. May contain duplicates.
  */
 protected static function _affected($dependency, $exclude = null)
 {
     $exclude = $exclude ?: '/(tests|webroot|resources|libraries|plugins)/';
     $classes = Libraries::find(true, compact('exclude') + array('recursive' => true));
     $dependency = ltrim($dependency, '\\');
     $affected = array();
     foreach ($classes as $class) {
         if (isset(static::$_cachedDepends[$class])) {
             $depends = static::$_cachedDepends[$class];
         } else {
             $depends = Inspector::dependencies($class);
             $depends = array_map(function ($c) {
                 return ltrim($c, '\\');
             }, $depends);
             static::$_cachedDepends[$class] = $depends;
         }
         if (in_array($dependency, $depends)) {
             $affected[] = $class;
         }
     }
     return $affected;
 }
开发者ID:unionofrad,项目名称:lithium,代码行数:29,代码来源:Affected.php

示例7: run

 /**
  * Runs main console application logic. Returns a list of 
  * available exercises by default. Otherwise runs the specified exercise.
  *
  * @param string $command 
  * @return void
  */
 public function run($command = null)
 {
     if ($command == null) {
         $this->out("{:heading}EXERCISES{:end}");
         foreach ($this->_exercises as $key => $exercise) {
             $library = strtok($exercise, '\\');
             $info = Inspector::info($exercise);
             $this->out($this->_pad($key . " {:blue}via {$library}{:end}"), 'heading');
             $this->out($this->_pad($info['description'] == '' ? '(No description)' : $info['description']), 2);
         }
         $this->stop();
     }
     if (isset($this->_exercises[$command])) {
         $className = $this->_exercises[$command];
         $exercise = new $className(array('command' => $this));
         $exercise->run();
     } else {
         $this->out("{:error}The exercise {:end}{:blue}\"{$command}\"{:end}{:error} you specified cannot be found. Please supply a valid exercise name.{:end}");
         $this->out();
         $this->stop(1);
     }
 }
开发者ID:raisinbread,项目名称:li3_exercises,代码行数:29,代码来源:Learn.php

示例8: run

 /**
  * Generate test cases in the given namespace.
  * `li3 create test model Post`
  * `li3 create test --library=li3_plugin model Post`
  *
  * @param string $type namespace of the class (e.g. model, controller, some.name.space).
  * @param string $name Name of class to test.
  * @return void
  */
 public function run($type = null, $name = null)
 {
     $library = Libraries::get($this->library);
     if (empty($library['prefix'])) {
         return false;
     }
     $namespace = $this->_namespace($type);
     $use = "\\{$library['prefix']}{$namespace}\\{$name}";
     $methods = array();
     if (class_exists($use)) {
         $methods = array();
         foreach (array_keys(Inspector::methods($use, 'extents')) as $method) {
             $methods[] = "\tpublic function test" . ucwords($method) . "() {}";
         }
     }
     $params = array('namespace' => "{$library['prefix']}tests\\cases\\{$namespace}", 'use' => $use, 'class' => "{$name}Test", 'methods' => join("\n", $methods));
     if ($this->_save($this->template, $params)) {
         $this->out("{$params['class']} created for {$name} in {$params['namespace']}.");
         return true;
     }
     return false;
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:31,代码来源:Test.php

示例9: getMap

 private function getMap($class)
 {
     $properties = Inspector::properties($class, array('public' => false));
     //parse out fields
     $fields = array();
     /** @var \ReflectionProperty $p */
     foreach ($properties as $p) {
         if (($p->getModifiers() & \ReflectionProperty::IS_PROTECTED) == \ReflectionProperty::IS_PROTECTED) {
             $name = $p->getName();
             if ($name[0] != '_') {
                 $fields[$name] = Docblock::comment($p->getDocComment());
             }
         }
     }
     //Parse out types
     $ret = array();
     foreach ($fields as $field => $data) {
         if (isset($data['tags']['var'])) {
             $ret[$field] = $this->dynamicType($data['tags']['var']);
         }
     }
     return $ret;
 }
开发者ID:splitice,项目名称:radical-db,代码行数:23,代码来源:Instance.php

示例10: respondsTo

 /**
  * Custom check to determine if our given magic methods can be responded to.
  *
  * @param  string  $method     Method name.
  * @param  bool    $internal   Interal call or not.
  * @return bool
  */
 public function respondsTo($method, $internal = false)
 {
     $class = $this->_model;
     $modelRespondsTo = false;
     $parentRespondsTo = parent::respondsTo($method, $internal);
     $staticRespondsTo = $class::respondsTo($method, $internal);
     if (method_exists($class, '_object')) {
         $model = $class::invokeMethod('_object');
         $modelRespondsTo = $model->respondsTo($method);
     } else {
         $modelRespondsTo = Inspector::isCallable($class, $method, $internal);
     }
     return $parentRespondsTo || $staticRespondsTo || $modelRespondsTo;
 }
开发者ID:davidpersson,项目名称:FrameworkBenchmarks,代码行数:21,代码来源:Entity.php

示例11: _parseClass

 public function _parseClass($class)
 {
     $data = array();
     // $methods = Inspector::methods($class, null, array('public' => false));
     $methods = get_class_methods($class);
     $properties = array_keys(get_class_vars($class));
     $ident = $class;
     $info = Inspector::info($ident);
     $info = Docblock::comment($info['comment']);
     $data = $this->_merge($data, array('id' => $info['description'], 'comments' => array($ident)));
     $this->_merge($data, array('id' => $info['text'], 'comments' => array($class)));
     foreach ($methods as $method) {
         $ident = "{$class}::{$method}()";
         $info = Inspector::info($ident);
         $info = Docblock::comment($info['comment']);
         $this->_merge($data, array('id' => $info['description'], 'comments' => array($ident)));
         $this->_merge($data, array('id' => $info['text'], 'comments' => array($ident)));
         if (isset($info['tags']['return'])) {
             $this->_merge($data, array('id' => $info['tags']['return'], 'comments' => array($ident)));
         }
         foreach (Set::extract($info, '/tags/params/text') as $text) {
             $this->_merge($data, array('id' => $text, 'comments' => array($ident)));
         }
     }
     foreach ($properties as $property) {
         $ident = "{$class}::\${$property}";
         $info = Inspector::info($ident);
         $info = Docblock::comment($info['comment']);
         $data = $this->_merge($data, array('id' => $info['description'], 'comments' => array($ident)));
         $data = $this->_merge($data, array('id' => $info['text'], 'comments' => array($ident)));
     }
     return $data;
 }
开发者ID:rmarscher,项目名称:li3_docs,代码行数:33,代码来源:Docs.php

示例12: testBadlyClosedDocblock

 /**
  * This docblock has an extra * in the closing element.
  *
  */
 public function testBadlyClosedDocblock()
 {
     $info = Inspector::info(__METHOD__ . '()');
     $description = 'This docblock has an extra * in the closing element.';
     $this->assertEqual($description, $info['description']);
     $this->assertEqual('', $info['text']);
 }
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:11,代码来源:DocblockTest.php

示例13: _properties

 /**
  * Get the properties for the class
  *
  * @param string $class
  * @param array $options
  * @return array
  */
 protected function _properties($class, $options = array())
 {
     $defaults = array('name' => null);
     $options += $defaults;
     $properties = Inspector::properties($class);
     $results = array();
     foreach ($properties as &$property) {
         $comment = Docblock::comment($property['docComment']);
         $description = trim($comment['description']);
         $type = isset($comment['tags']['var']) ? strtok($comment['tags']['var'], ' ') : null;
         $name = str_replace('_', '-', Inflector::underscore($property['name']));
         $usage = $type == 'boolean' ? "-{$name}" : "--{$name}=" . strtoupper($name);
         $results[$name] = compact('name', 'description', 'type', 'usage');
         if ($name == $options['name']) {
             return array($name => $results[$name]);
         }
     }
     return $results;
 }
开发者ID:EHER,项目名称:chegamos,代码行数:26,代码来源:Help.php

示例14: respondsTo

 /**
  * Will determine if a method can be called.
  *
  * @param  string  $method     Method name.
  * @param  bool    $internal   Interal call or not.
  * @return bool
  */
 public static function respondsTo($method, $internal = false)
 {
     return Inspector::isCallable(get_called_class(), $method, $internal);
 }
开发者ID:nilamdoc,项目名称:KYCGlobal,代码行数:11,代码来源:StaticObject.php

示例15: _reportException

 /**
  * Convert an exception object to an exception result array for test reporting.
  *
  * @param object $exception The exception object to report on. Statistics are gathered and
  *               added to the reporting stack contained in `Unit::$_results`.
  * @param string $lineFlag
  * @return void
  * @todo Refactor so that reporters handle trace formatting.
  */
 protected function _reportException($exception, $lineFlag = null)
 {
     $initFrame = current($exception['trace']) + array('class' => '-', 'function' => '-');
     foreach ($exception['trace'] as $frame) {
         if (isset($scopedFrame)) {
             break;
         }
         if (!class_exists('lithium\\analysis\\Inspector')) {
             continue;
         }
         if (isset($frame['class']) && in_array($frame['class'], Inspector::parents($this))) {
             $scopedFrame = $frame;
         }
     }
     $trace = $exception['trace'];
     unset($exception['trace']);
     $this->_result('exception', $exception + array('class' => $initFrame['class'], 'method' => $initFrame['function'], 'trace' => Debugger::trace(array('trace' => $trace, 'format' => '{:functionRef}, line {:line}', 'includeScope' => false, 'scope' => array_filter(array('functionRef' => __NAMESPACE__ . '\\{closure}', 'line' => $lineFlag))))));
 }
开发者ID:kdambekalns,项目名称:framework-benchs,代码行数:27,代码来源:Unit.php


注:本文中的lithium\analysis\Inspector类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。