repo
stringlengths
6
63
path
stringlengths
5
140
func_name
stringlengths
3
151
original_string
stringlengths
84
13k
language
stringclasses
1 value
code
stringlengths
84
13k
code_tokens
list
docstring
stringlengths
3
47.2k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
91
247
partition
stringclasses
1 value
kahlan/kahlan
src/Block.php
Block.parents
public function parents($current = false) { $instances = []; $instance = $current ? $this : $this->_parent; while ($instance !== null) { $instances[] = $instance; $instance = $instance->_parent; } return array_reverse($instances); }
php
public function parents($current = false) { $instances = []; $instance = $current ? $this : $this->_parent; while ($instance !== null) { $instances[] = $instance; $instance = $instance->_parent; } return array_reverse($instances); }
[ "public", "function", "parents", "(", "$", "current", "=", "false", ")", "{", "$", "instances", "=", "[", "]", ";", "$", "instance", "=", "$", "current", "?", "$", "this", ":", "$", "this", "->", "_parent", ";", "while", "(", "$", "instance", "!=="...
Return all parent block instances. @param boolean $current If `true` include `$this` to the list. @return array.
[ "Return", "all", "parent", "block", "instances", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block.php#L265-L275
train
kahlan/kahlan
src/Block.php
Block.messages
public function messages() { $messages = []; $instances = $this->parents(true); foreach ($instances as $instance) { $messages[] = $instance->message(); } return $messages; }
php
public function messages() { $messages = []; $instances = $this->parents(true); foreach ($instances as $instance) { $messages[] = $instance->message(); } return $messages; }
[ "public", "function", "messages", "(", ")", "{", "$", "messages", "=", "[", "]", ";", "$", "instances", "=", "$", "this", "->", "parents", "(", "true", ")", ";", "foreach", "(", "$", "instances", "as", "$", "instance", ")", "{", "$", "messages", "[...
Return all messages upon the root. @return array
[ "Return", "all", "messages", "upon", "the", "root", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block.php#L282-L290
train
kahlan/kahlan
src/Block.php
Block.log
public function log($type = null, $data = []) { if (!func_num_args()) { return $this->_log; } $this->report($type, $this->log()->add($type, $data)); }
php
public function log($type = null, $data = []) { if (!func_num_args()) { return $this->_log; } $this->report($type, $this->log()->add($type, $data)); }
[ "public", "function", "log", "(", "$", "type", "=", "null", ",", "$", "data", "=", "[", "]", ")", "{", "if", "(", "!", "func_num_args", "(", ")", ")", "{", "return", "$", "this", "->", "_log", ";", "}", "$", "this", "->", "report", "(", "$", ...
Dispatch a report. @param object $log The report object to log.
[ "Dispatch", "a", "report", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block.php#L320-L326
train
kahlan/kahlan
src/Block.php
Block._process
protected function _process($options = []) { $suite = $this->suite(); if ($suite->root()->focused() && !$this->focused()) { return; } $this->_passed = true; if ($this->excluded()) { $this->log()->type('excluded'); $this->summary()->log($this->log()); $this->report('specEnd', $this->log()); return; } $result = null; $suite::push($this); if ($suite::$PHP >= 7 && !defined('HHVM_VERSION')) { try { $this->_blockStart(); try { $result = $this->_execute(); } catch (Throwable $exception) { $this->_exception($exception); } $this->_blockEnd(); } catch (Throwable $exception) { $this->_exception($exception, true); $this->_blockEnd(!$exception instanceof SkipException); } } else { try { $this->_blockStart(); try { $result = $this->_execute(); } catch (Exception $exception) { $this->_exception($exception); } $this->_blockEnd(); } catch (Exception $exception) { $this->_exception($exception, true); $this->_blockEnd(!$exception instanceof SkipException); } } $suite::pop(); return $this->_return = $result; }
php
protected function _process($options = []) { $suite = $this->suite(); if ($suite->root()->focused() && !$this->focused()) { return; } $this->_passed = true; if ($this->excluded()) { $this->log()->type('excluded'); $this->summary()->log($this->log()); $this->report('specEnd', $this->log()); return; } $result = null; $suite::push($this); if ($suite::$PHP >= 7 && !defined('HHVM_VERSION')) { try { $this->_blockStart(); try { $result = $this->_execute(); } catch (Throwable $exception) { $this->_exception($exception); } $this->_blockEnd(); } catch (Throwable $exception) { $this->_exception($exception, true); $this->_blockEnd(!$exception instanceof SkipException); } } else { try { $this->_blockStart(); try { $result = $this->_execute(); } catch (Exception $exception) { $this->_exception($exception); } $this->_blockEnd(); } catch (Exception $exception) { $this->_exception($exception, true); $this->_blockEnd(!$exception instanceof SkipException); } } $suite::pop(); return $this->_return = $result; }
[ "protected", "function", "_process", "(", "$", "options", "=", "[", "]", ")", "{", "$", "suite", "=", "$", "this", "->", "suite", "(", ")", ";", "if", "(", "$", "suite", "->", "root", "(", ")", "->", "focused", "(", ")", "&&", "!", "$", "this",...
Block processing. @param array $options Process options.
[ "Block", "processing", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block.php#L358-L408
train
kahlan/kahlan
src/Block.php
Block._exception
protected function _exception($exception, $inEachHook = false) { if ($exception instanceof SkipException) { !$inEachHook ? $this->log()->type('skipped') : $this->_skipChildren($exception); return; } $this->_passed = false; $this->log()->type('errored'); $this->log()->exception($exception); }
php
protected function _exception($exception, $inEachHook = false) { if ($exception instanceof SkipException) { !$inEachHook ? $this->log()->type('skipped') : $this->_skipChildren($exception); return; } $this->_passed = false; $this->log()->type('errored'); $this->log()->exception($exception); }
[ "protected", "function", "_exception", "(", "$", "exception", ",", "$", "inEachHook", "=", "false", ")", "{", "if", "(", "$", "exception", "instanceof", "SkipException", ")", "{", "!", "$", "inEachHook", "?", "$", "this", "->", "log", "(", ")", "->", "...
Manage catched exception. @param Exception $exception The catched exception. @param boolean $inEachHook Indicates if the exception occurs in a beforeEach/afterEach hook.
[ "Manage", "catched", "exception", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block.php#L446-L455
train
kahlan/kahlan
src/Block.php
Block._emitFocus
protected function _emitFocus() { $this->summary()->add('focused', $this); $instances = $this->parents(true); foreach ($instances as $instance) { $instance->type('focus'); } }
php
protected function _emitFocus() { $this->summary()->add('focused', $this); $instances = $this->parents(true); foreach ($instances as $instance) { $instance->type('focus'); } }
[ "protected", "function", "_emitFocus", "(", ")", "{", "$", "this", "->", "summary", "(", ")", "->", "add", "(", "'focused'", ",", "$", "this", ")", ";", "$", "instances", "=", "$", "this", "->", "parents", "(", "true", ")", ";", "foreach", "(", "$"...
Apply focus up to the root.
[ "Apply", "focus", "up", "to", "the", "root", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block.php#L487-L495
train
kahlan/kahlan
src/Matcher/ToReceive.php
ToReceive._check
protected function _check($reference) { $isString = is_string($reference); if ($isString) { if (!class_exists($reference)) { throw new InvalidArgumentException("Can't Spy the unexisting class `{$reference}`."); } $reflection = Inspector::inspect($reference); } else { $reflection = Inspector::inspect(get_class($reference)); } if (!$reflection->isInternal()) { return; } if (!$isString) { throw new InvalidArgumentException("Can't Spy built-in PHP instances, create a test double using `Double::instance()`."); } }
php
protected function _check($reference) { $isString = is_string($reference); if ($isString) { if (!class_exists($reference)) { throw new InvalidArgumentException("Can't Spy the unexisting class `{$reference}`."); } $reflection = Inspector::inspect($reference); } else { $reflection = Inspector::inspect(get_class($reference)); } if (!$reflection->isInternal()) { return; } if (!$isString) { throw new InvalidArgumentException("Can't Spy built-in PHP instances, create a test double using `Double::instance()`."); } }
[ "protected", "function", "_check", "(", "$", "reference", ")", "{", "$", "isString", "=", "is_string", "(", "$", "reference", ")", ";", "if", "(", "$", "isString", ")", "{", "if", "(", "!", "class_exists", "(", "$", "reference", ")", ")", "{", "throw...
Check the actual value can receive messages. @param mixed $reference An instance or a fully-namespaced class name.
[ "Check", "the", "actual", "value", "can", "receive", "messages", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToReceive.php#L130-L148
train
kahlan/kahlan
src/Matcher/ToReceive.php
ToReceive._reference
protected function _reference($reference) { if (!is_string($reference)) { return $reference; } $pos = strrpos($reference, '\\'); if ($pos !== false) { $namespace = substr($reference, 0, $pos); $basename = substr($reference, $pos + 1); } else { $namespace = null; $basename = $reference; } $substitute = null; $reference = Monkey::patched($namespace, $basename, false, $substitute); return $substitute ?: $reference; }
php
protected function _reference($reference) { if (!is_string($reference)) { return $reference; } $pos = strrpos($reference, '\\'); if ($pos !== false) { $namespace = substr($reference, 0, $pos); $basename = substr($reference, $pos + 1); } else { $namespace = null; $basename = $reference; } $substitute = null; $reference = Monkey::patched($namespace, $basename, false, $substitute); return $substitute ?: $reference; }
[ "protected", "function", "_reference", "(", "$", "reference", ")", "{", "if", "(", "!", "is_string", "(", "$", "reference", ")", ")", "{", "return", "$", "reference", ";", "}", "$", "pos", "=", "strrpos", "(", "$", "reference", ",", "'\\\\'", ")", ";...
Return the actual reference which must be used. @param mixed $reference An instance or a fully-namespaced class name. @param mixed The reference or the monkey patched one if exist.
[ "Return", "the", "actual", "reference", "which", "must", "be", "used", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToReceive.php#L156-L174
train
kahlan/kahlan
src/Matcher/ToReceive.php
ToReceive._watch
protected function _watch($message) { $reference = $message->reference(); if (!$reference) { Suite::register($message->name()); return $message; } if (is_object($reference)) { Suite::register(get_class($reference)); } Suite::register(Suite::hash($reference)); return $message; }
php
protected function _watch($message) { $reference = $message->reference(); if (!$reference) { Suite::register($message->name()); return $message; } if (is_object($reference)) { Suite::register(get_class($reference)); } Suite::register(Suite::hash($reference)); return $message; }
[ "protected", "function", "_watch", "(", "$", "message", ")", "{", "$", "reference", "=", "$", "message", "->", "reference", "(", ")", ";", "if", "(", "!", "$", "reference", ")", "{", "Suite", "::", "register", "(", "$", "message", "->", "name", "(", ...
Watch a message. @param Message $message The message instance @return Message
[ "Watch", "a", "message", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToReceive.php#L183-L195
train
kahlan/kahlan
src/Matcher/ToReceive.php
ToReceive.resolve
public function resolve() { $startIndex = $this->_ordered ? Calls::lastFindIndex() : 0; $report = Calls::find($this->_messages, $startIndex, $this->times()); $this->_report = $report; $this->_buildDescription($startIndex); return $report['success']; }
php
public function resolve() { $startIndex = $this->_ordered ? Calls::lastFindIndex() : 0; $report = Calls::find($this->_messages, $startIndex, $this->times()); $this->_report = $report; $this->_buildDescription($startIndex); return $report['success']; }
[ "public", "function", "resolve", "(", ")", "{", "$", "startIndex", "=", "$", "this", "->", "_ordered", "?", "Calls", "::", "lastFindIndex", "(", ")", ":", "0", ";", "$", "report", "=", "Calls", "::", "find", "(", "$", "this", "->", "_messages", ",", ...
Resolves the matching. @return boolean Returns `true` if successfully resolved, `false` otherwise.
[ "Resolves", "the", "matching", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToReceive.php#L275-L282
train
kahlan/kahlan
src/Reporter/Verbose.php
Verbose.suiteStart
public function suiteStart($suite = null) { $messages = $suite->messages(); if (count($messages) === 1) { return; } if (count($messages) === 2) { $this->write("\n"); } $message = end($messages); $this->write("{$message}\n"); $this->_indent++; }
php
public function suiteStart($suite = null) { $messages = $suite->messages(); if (count($messages) === 1) { return; } if (count($messages) === 2) { $this->write("\n"); } $message = end($messages); $this->write("{$message}\n"); $this->_indent++; }
[ "public", "function", "suiteStart", "(", "$", "suite", "=", "null", ")", "{", "$", "messages", "=", "$", "suite", "->", "messages", "(", ")", ";", "if", "(", "count", "(", "$", "messages", ")", "===", "1", ")", "{", "return", ";", "}", "if", "(",...
Callback called on a suite start. @param object $suite The suite instance.
[ "Callback", "called", "on", "a", "suite", "start", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Verbose.php#L23-L35
train
kahlan/kahlan
src/Scope.php
Scope.given
public function given($name, $closure) { if (isset(static::$_blacklist[$name])) { throw new Exception("Sorry `{$name}` is a reserved keyword, it can't be used as a scope variable."); } $given = new Given($closure); if (array_key_exists($name, $this->_given)) { $given->{$name} = $this->_given[$name](Suite::current()->scope()); } $this->_given[$name] = $given; return $this; }
php
public function given($name, $closure) { if (isset(static::$_blacklist[$name])) { throw new Exception("Sorry `{$name}` is a reserved keyword, it can't be used as a scope variable."); } $given = new Given($closure); if (array_key_exists($name, $this->_given)) { $given->{$name} = $this->_given[$name](Suite::current()->scope()); } $this->_given[$name] = $given; return $this; }
[ "public", "function", "given", "(", "$", "name", ",", "$", "closure", ")", "{", "if", "(", "isset", "(", "static", "::", "$", "_blacklist", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "Exception", "(", "\"Sorry `{$name}` is a reserved keyword, it...
Sets a lazy loaded data. @param string $name The lazy loaded variable name. @param Closure $closure The lazily executed closure. @return object
[ "Sets", "a", "lazy", "loaded", "data", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Scope.php#L155-L167
train
kahlan/kahlan
src/Reporter/Coverage/Metrics.php
Metrics.add
public function add($name, $metrics) { $parts = $this->_parseName($name); $this->_merge($metrics); $current = $this; $length = count($parts); foreach ($parts as $index => $part) { list($name, $type) = $part; if (!isset($current->_children[$name])) { $current->_children[$name] = new static([ 'name' => $name, 'parent' => $current, 'type' => $type ]); } uksort($current->_children, function ($a, $b) { $isFunction1 = substr($a, -2) === '()'; $isFunction2 = substr($b, -2) === '()'; if ($isFunction1 === $isFunction2) { return strcmp($a, $b); } return $isFunction1 ? -1 : 1; }); $current = $current->_children[$name]; $current->_merge($metrics, $index === $length - 1); } }
php
public function add($name, $metrics) { $parts = $this->_parseName($name); $this->_merge($metrics); $current = $this; $length = count($parts); foreach ($parts as $index => $part) { list($name, $type) = $part; if (!isset($current->_children[$name])) { $current->_children[$name] = new static([ 'name' => $name, 'parent' => $current, 'type' => $type ]); } uksort($current->_children, function ($a, $b) { $isFunction1 = substr($a, -2) === '()'; $isFunction2 = substr($b, -2) === '()'; if ($isFunction1 === $isFunction2) { return strcmp($a, $b); } return $isFunction1 ? -1 : 1; }); $current = $current->_children[$name]; $current->_merge($metrics, $index === $length - 1); } }
[ "public", "function", "add", "(", "$", "name", ",", "$", "metrics", ")", "{", "$", "parts", "=", "$", "this", "->", "_parseName", "(", "$", "name", ")", ";", "$", "this", "->", "_merge", "(", "$", "metrics", ")", ";", "$", "current", "=", "$", ...
Adds some metrics to the current metrics. @param string $name The name reference of the metrics. Possible values are: `'namespace'`, `'class' or 'function'. @param array The metrics array to add.
[ "Adds", "some", "metrics", "to", "the", "current", "metrics", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Metrics.php#L151-L179
train
kahlan/kahlan
src/Reporter/Coverage/Metrics.php
Metrics.get
public function get($name = null) { $parts = $this->_parseName($name); $child = $this; foreach ($parts as $part) { list($name) = $part; if (!isset($child->_children[$name])) { return; } $child = $child->_children[$name]; } return $child; }
php
public function get($name = null) { $parts = $this->_parseName($name); $child = $this; foreach ($parts as $part) { list($name) = $part; if (!isset($child->_children[$name])) { return; } $child = $child->_children[$name]; } return $child; }
[ "public", "function", "get", "(", "$", "name", "=", "null", ")", "{", "$", "parts", "=", "$", "this", "->", "_parseName", "(", "$", "name", ")", ";", "$", "child", "=", "$", "this", ";", "foreach", "(", "$", "parts", "as", "$", "part", ")", "{"...
Gets the metrics from a name. @param string $name The name reference of the metrics. @return object The metrics instance.
[ "Gets", "the", "metrics", "from", "a", "name", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Metrics.php#L187-L200
train
kahlan/kahlan
src/Reporter/Coverage/Metrics.php
Metrics.children
public function children($name = null) { $child = $this->get($name); if (!$child) { return []; } return $child->_children; }
php
public function children($name = null) { $child = $this->get($name); if (!$child) { return []; } return $child->_children; }
[ "public", "function", "children", "(", "$", "name", "=", "null", ")", "{", "$", "child", "=", "$", "this", "->", "get", "(", "$", "name", ")", ";", "if", "(", "!", "$", "child", ")", "{", "return", "[", "]", ";", "}", "return", "$", "child", ...
Gets the children of the current metrics. @param string $name The name reference of the metrics. @return array The metrics children.
[ "Gets", "the", "children", "of", "the", "current", "metrics", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Metrics.php#L208-L215
train
kahlan/kahlan
src/Reporter/Coverage/Metrics.php
Metrics._parseName
protected function _parseName($name) { $result = []; $parts = preg_split('~([^\\\]*\\\?)~', $name, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $last = array_pop($parts); if (!$last) { return []; } foreach ($parts as $name) { $result[] = [$name, 'namespace']; } if (strpos($last, '::') !== false) { list($name, $subname) = explode('::', $last, 2); $result[] = [$name, 'class']; $result[] = [$subname, 'method']; } elseif (preg_match('~\(\)$~', $last)) { $result[] = [$last, 'function']; } else { $result[] = [$last, substr($last, -1) === '\\' ? 'namespace' : 'class']; } return $result; }
php
protected function _parseName($name) { $result = []; $parts = preg_split('~([^\\\]*\\\?)~', $name, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); $last = array_pop($parts); if (!$last) { return []; } foreach ($parts as $name) { $result[] = [$name, 'namespace']; } if (strpos($last, '::') !== false) { list($name, $subname) = explode('::', $last, 2); $result[] = [$name, 'class']; $result[] = [$subname, 'method']; } elseif (preg_match('~\(\)$~', $last)) { $result[] = [$last, 'function']; } else { $result[] = [$last, substr($last, -1) === '\\' ? 'namespace' : 'class']; } return $result; }
[ "protected", "function", "_parseName", "(", "$", "name", ")", "{", "$", "result", "=", "[", "]", ";", "$", "parts", "=", "preg_split", "(", "'~([^\\\\\\]*\\\\\\?)~'", ",", "$", "name", ",", "-", "1", ",", "PREG_SPLIT_DELIM_CAPTURE", "|", "PREG_SPLIT_NO_EMPTY...
Gets meta info of a metrics from a name reference.. @param string $name The name reference of the metrics. @return array The parsed name.
[ "Gets", "meta", "info", "of", "a", "metrics", "from", "a", "name", "reference", ".." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Metrics.php#L223-L248
train
kahlan/kahlan
src/Reporter/Coverage/Metrics.php
Metrics._merge
protected function _merge($metrics = [], $line = false) { $defaults = [ 'loc' => [], 'nlloc' => [], 'lloc' => [], 'cloc' => [], 'files' => [], 'methods' => 0, 'cmethods' => 0 ]; $metrics += $defaults; foreach (['loc', 'nlloc', 'lloc', 'cloc', 'coverage', 'files', 'methods', 'cmethods'] as $name) { $metrics[$name] += $this->_metrics[$name]; } if (!$line) { unset($metrics['line']); } $this->data($metrics); }
php
protected function _merge($metrics = [], $line = false) { $defaults = [ 'loc' => [], 'nlloc' => [], 'lloc' => [], 'cloc' => [], 'files' => [], 'methods' => 0, 'cmethods' => 0 ]; $metrics += $defaults; foreach (['loc', 'nlloc', 'lloc', 'cloc', 'coverage', 'files', 'methods', 'cmethods'] as $name) { $metrics[$name] += $this->_metrics[$name]; } if (!$line) { unset($metrics['line']); } $this->data($metrics); }
[ "protected", "function", "_merge", "(", "$", "metrics", "=", "[", "]", ",", "$", "line", "=", "false", ")", "{", "$", "defaults", "=", "[", "'loc'", "=>", "[", "]", ",", "'nlloc'", "=>", "[", "]", ",", "'lloc'", "=>", "[", "]", ",", "'cloc'", "...
Merges some given metrics to the existing metrics . @param array $metrics Metrics data to merge. @param boolean $line Set to `true` for function only
[ "Merges", "some", "given", "metrics", "to", "the", "existing", "metrics", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Metrics.php#L256-L276
train
kahlan/kahlan
src/Analysis/Inspector.php
Inspector.parameters
public static function parameters($class, $method, $data = null) { $params = []; $reflexion = Inspector::inspect($class); $parameters = $reflexion->getMethod($method)->getParameters(); if ($data === null) { return $parameters; } foreach ($data as $key => $value) { $name = $key; if ($parameters) { $parameter = array_shift($parameters); $name = $parameter->getName(); } $params[$name] = $value; } foreach ($parameters as $parameter) { if ($parameter->isDefaultValueAvailable()) { $params[$parameter->getName()] = $parameter->getDefaultValue(); } } return $params; }
php
public static function parameters($class, $method, $data = null) { $params = []; $reflexion = Inspector::inspect($class); $parameters = $reflexion->getMethod($method)->getParameters(); if ($data === null) { return $parameters; } foreach ($data as $key => $value) { $name = $key; if ($parameters) { $parameter = array_shift($parameters); $name = $parameter->getName(); } $params[$name] = $value; } foreach ($parameters as $parameter) { if ($parameter->isDefaultValueAvailable()) { $params[$parameter->getName()] = $parameter->getDefaultValue(); } } return $params; }
[ "public", "static", "function", "parameters", "(", "$", "class", ",", "$", "method", ",", "$", "data", "=", "null", ")", "{", "$", "params", "=", "[", "]", ";", "$", "reflexion", "=", "Inspector", "::", "inspect", "(", "$", "class", ")", ";", "$", ...
Gets the parameters array of a class method. @param $class The class name. @param $method The method name. @param $data The default values. @return array The parameters array.
[ "Gets", "the", "parameters", "array", "of", "a", "class", "method", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Inspector.php#L37-L59
train
kahlan/kahlan
src/Analysis/Inspector.php
Inspector.typehint
public static function typehint($parameter) { $typehint = ''; if ($parameter->getClass()) { $typehint = '\\' . $parameter->getClass()->getName(); } elseif (preg_match('/.*?\[ \<[^\>]+\> (?:HH\\\)?(\w+)(.*?)\$/', (string) $parameter, $match)) { $typehint = $match[1]; if ($typehint === 'integer') { $typehint = 'int'; } elseif ($typehint === 'boolean') { $typehint = 'bool'; } elseif ($typehint === 'mixed') { $typehint = ''; } } return $typehint; }
php
public static function typehint($parameter) { $typehint = ''; if ($parameter->getClass()) { $typehint = '\\' . $parameter->getClass()->getName(); } elseif (preg_match('/.*?\[ \<[^\>]+\> (?:HH\\\)?(\w+)(.*?)\$/', (string) $parameter, $match)) { $typehint = $match[1]; if ($typehint === 'integer') { $typehint = 'int'; } elseif ($typehint === 'boolean') { $typehint = 'bool'; } elseif ($typehint === 'mixed') { $typehint = ''; } } return $typehint; }
[ "public", "static", "function", "typehint", "(", "$", "parameter", ")", "{", "$", "typehint", "=", "''", ";", "if", "(", "$", "parameter", "->", "getClass", "(", ")", ")", "{", "$", "typehint", "=", "'\\\\'", ".", "$", "parameter", "->", "getClass", ...
Returns the type hint of a `ReflectionParameter` instance. @param object $parameter A instance of `ReflectionParameter`. @return string The parameter type hint.
[ "Returns", "the", "type", "hint", "of", "a", "ReflectionParameter", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Inspector.php#L67-L83
train
kahlan/kahlan
spec/Mock/Collection.php
Collection.prev
public function prev() { $value = prev($this->_data); return key($this->_data) !== null ? $value : null; }
php
public function prev() { $value = prev($this->_data); return key($this->_data) !== null ? $value : null; }
[ "public", "function", "prev", "(", ")", "{", "$", "value", "=", "prev", "(", "$", "this", "->", "_data", ")", ";", "return", "key", "(", "$", "this", "->", "_data", ")", "!==", "null", "?", "$", "value", ":", "null", ";", "}" ]
Moves backward to the previous item. @return mixed The previous item.
[ "Moves", "backward", "to", "the", "previous", "item", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/spec/Mock/Collection.php#L170-L174
train
kahlan/kahlan
src/Cli/CommandLine.php
CommandLine.parse
public function parse($argv, $override = true) { $exists = []; $override ? $this->_values = $this->_defaults : $exists = array_fill_keys(array_keys($this->_values), true); foreach ($argv as $arg) { if ($arg === '--') { break; } if ($arg[0] === '-') { list($name, $value) = $this->_parse(ltrim($arg, '-')); if ($override || !isset($exists[$name])) { $this->add($name, $value); } } } return $this->get(); }
php
public function parse($argv, $override = true) { $exists = []; $override ? $this->_values = $this->_defaults : $exists = array_fill_keys(array_keys($this->_values), true); foreach ($argv as $arg) { if ($arg === '--') { break; } if ($arg[0] === '-') { list($name, $value) = $this->_parse(ltrim($arg, '-')); if ($override || !isset($exists[$name])) { $this->add($name, $value); } } } return $this->get(); }
[ "public", "function", "parse", "(", "$", "argv", ",", "$", "override", "=", "true", ")", "{", "$", "exists", "=", "[", "]", ";", "$", "override", "?", "$", "this", "->", "_values", "=", "$", "this", "->", "_defaults", ":", "$", "exists", "=", "ar...
Parses a command line argv. @param array $argv An argv data. @param boolean $override If set to `false` it doesn't override already setted data. @return array The parsed attributes
[ "Parses", "a", "command", "line", "argv", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Cli/CommandLine.php#L97-L115
train
kahlan/kahlan
src/Cli/CommandLine.php
CommandLine.exists
public function exists($name) { list($key, $extra) = $this->_splitOptionName($name); if (isset($this->_values[$key]) && is_array($this->_values[$key]) && array_key_exists($extra, $this->_values[$key])) { return true; } if (isset($this->_options[$name])) { return isset($this->_options[$name]['default']); } return false; }
php
public function exists($name) { list($key, $extra) = $this->_splitOptionName($name); if (isset($this->_values[$key]) && is_array($this->_values[$key]) && array_key_exists($extra, $this->_values[$key])) { return true; } if (isset($this->_options[$name])) { return isset($this->_options[$name]['default']); } return false; }
[ "public", "function", "exists", "(", "$", "name", ")", "{", "list", "(", "$", "key", ",", "$", "extra", ")", "=", "$", "this", "->", "_splitOptionName", "(", "$", "name", ")", ";", "if", "(", "isset", "(", "$", "this", "->", "_values", "[", "$", ...
Checks if an option has been setted. @param string $name The name of the option. @return boolean
[ "Checks", "if", "an", "option", "has", "been", "setted", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Cli/CommandLine.php#L142-L152
train
kahlan/kahlan
src/Cli/CommandLine.php
CommandLine.set
public function set($name, $value) { list($key, $extra) = $this->_splitOptionName($name); if ($extra && !isset($this->_options[$key])) { $this->option($key, ['group' => true, 'array' => true]); } return $this->_values[$key][$extra] = $value; }
php
public function set($name, $value) { list($key, $extra) = $this->_splitOptionName($name); if ($extra && !isset($this->_options[$key])) { $this->option($key, ['group' => true, 'array' => true]); } return $this->_values[$key][$extra] = $value; }
[ "public", "function", "set", "(", "$", "name", ",", "$", "value", ")", "{", "list", "(", "$", "key", ",", "$", "extra", ")", "=", "$", "this", "->", "_splitOptionName", "(", "$", "name", ")", ";", "if", "(", "$", "extra", "&&", "!", "isset", "(...
Sets the value of a specific option. @param string $name The name of the option. @param mixed $value The value of the option to set. @return array The setted value.
[ "Sets", "the", "value", "of", "a", "specific", "option", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Cli/CommandLine.php#L161-L168
train
kahlan/kahlan
src/Cli/CommandLine.php
CommandLine.get
public function get($name = null) { if (func_num_args()) { return $this->_get($name); } $result = []; foreach ($this->_values as $key => $data) { foreach ($data as $extra => $value) { if ($extra === '') { $result[$key] = $this->_get($key); } else { $result[$key][$extra] = $this->_get($key . ':' . $extra); } } } return $result; }
php
public function get($name = null) { if (func_num_args()) { return $this->_get($name); } $result = []; foreach ($this->_values as $key => $data) { foreach ($data as $extra => $value) { if ($extra === '') { $result[$key] = $this->_get($key); } else { $result[$key][$extra] = $this->_get($key . ':' . $extra); } } } return $result; }
[ "public", "function", "get", "(", "$", "name", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", ")", "{", "return", "$", "this", "->", "_get", "(", "$", "name", ")", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", ...
Gets the value of a specific option. @param string $name The name of the option. @return array The value.
[ "Gets", "the", "value", "of", "a", "specific", "option", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Cli/CommandLine.php#L196-L212
train
kahlan/kahlan
src/Cli/CommandLine.php
CommandLine.cast
public function cast($value, $type, $array = false) { if (is_array($value)) { $result = []; foreach ($value as $key => $item) { $result[$key] = $this->cast($item, $type); } return $result; } if ($type === 'boolean') { $value = ($value === 'false' || $value === '0' || $value === false || $value === null) ? false : true; } elseif ($type === 'numeric') { $value = $value !== null ? (int) $value + 0 : 1; } elseif ($type === 'string') { $value = ($value !== true && $value !== null) ? (string) $value : null; } if ($array) { return $value ? (array) $value : []; } return $value; }
php
public function cast($value, $type, $array = false) { if (is_array($value)) { $result = []; foreach ($value as $key => $item) { $result[$key] = $this->cast($item, $type); } return $result; } if ($type === 'boolean') { $value = ($value === 'false' || $value === '0' || $value === false || $value === null) ? false : true; } elseif ($type === 'numeric') { $value = $value !== null ? (int) $value + 0 : 1; } elseif ($type === 'string') { $value = ($value !== true && $value !== null) ? (string) $value : null; } if ($array) { return $value ? (array) $value : []; } return $value; }
[ "public", "function", "cast", "(", "$", "value", ",", "$", "type", ",", "$", "array", "=", "false", ")", "{", "if", "(", "is_array", "(", "$", "value", ")", ")", "{", "$", "result", "=", "[", "]", ";", "foreach", "(", "$", "value", "as", "$", ...
Casts a value according to the option attributes. @param string $value The value to cast. @param string $type The type of the value. @param boolean $array If `true`, the argument value is considered to be an array. @return array The casted value.
[ "Casts", "a", "value", "according", "to", "the", "option", "attributes", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Cli/CommandLine.php#L256-L276
train
kahlan/kahlan
src/Jit/Parser.php
Parser._closeCurly
protected function _closeCurly() { $current = $this->_states['current']; $this->_codeNode(); $current->close = '}'; if ($current->type === 'function') { if ($current->isClosure) { $current->close .= $this->_stream->next([')', ';', ',', ']']); $this->_states['num'] += substr_count($current->close, "\n"); } } elseif ($current->type === 'namespace') { $this->_flushUses(); } $this->_states['current'] = $current->parent; if (!$this->_states['lines']) { return; } $current->lines['stop'] = $this->_states['num']; $current->parent->lines['stop'] = $this->_states['num']; }
php
protected function _closeCurly() { $current = $this->_states['current']; $this->_codeNode(); $current->close = '}'; if ($current->type === 'function') { if ($current->isClosure) { $current->close .= $this->_stream->next([')', ';', ',', ']']); $this->_states['num'] += substr_count($current->close, "\n"); } } elseif ($current->type === 'namespace') { $this->_flushUses(); } $this->_states['current'] = $current->parent; if (!$this->_states['lines']) { return; } $current->lines['stop'] = $this->_states['num']; $current->parent->lines['stop'] = $this->_states['num']; }
[ "protected", "function", "_closeCurly", "(", ")", "{", "$", "current", "=", "$", "this", "->", "_states", "[", "'current'", "]", ";", "$", "this", "->", "_codeNode", "(", ")", ";", "$", "current", "->", "close", "=", "'}'", ";", "if", "(", "$", "cu...
Manage curly brackets.
[ "Manage", "curly", "brackets", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L227-L251
train
kahlan/kahlan
src/Jit/Parser.php
Parser._declareNode
protected function _declareNode() { $this->_codeNode(); $body = $this->_stream->current() . $this->_stream->next([';', '{']); if (preg_match('~ticks~i', $body, $matches)) { $isBlock = substr($body, -1) === '{'; if ($isBlock) { $body = substr($body, 0, -1); } $node = new NodeDef($body, 'declare'); $this->_contextualize($node); if ($isBlock) { $this->_states['body'] .= '{'; $this->_states['current'] = $this->_codeNode(); } return $node; } $this->_states['body'] .= $body; $node = new BlockDef($body, 'declare'); $node->hasMethods = false; $this->_states['current'] = $this->_root; $this->_contextualize($node); return $this->_states['current'] = $node; }
php
protected function _declareNode() { $this->_codeNode(); $body = $this->_stream->current() . $this->_stream->next([';', '{']); if (preg_match('~ticks~i', $body, $matches)) { $isBlock = substr($body, -1) === '{'; if ($isBlock) { $body = substr($body, 0, -1); } $node = new NodeDef($body, 'declare'); $this->_contextualize($node); if ($isBlock) { $this->_states['body'] .= '{'; $this->_states['current'] = $this->_codeNode(); } return $node; } $this->_states['body'] .= $body; $node = new BlockDef($body, 'declare'); $node->hasMethods = false; $this->_states['current'] = $this->_root; $this->_contextualize($node); return $this->_states['current'] = $node; }
[ "protected", "function", "_declareNode", "(", ")", "{", "$", "this", "->", "_codeNode", "(", ")", ";", "$", "body", "=", "$", "this", "->", "_stream", "->", "current", "(", ")", ".", "$", "this", "->", "_stream", "->", "next", "(", "[", "';'", ",",...
Build a declare node.
[ "Build", "a", "declare", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L299-L324
train
kahlan/kahlan
src/Jit/Parser.php
Parser._namespaceNode
protected function _namespaceNode() { $this->_codeNode(); $this->_flushUses(); $body = $this->_stream->current(); $name = $this->_stream->next([';', '{']); $this->_states['body'] .= $body; $node = new BlockDef($body . $name, 'namespace'); $node->hasMethods = false; $node->name = trim(substr($name, 0, -1)); $this->_states['current'] = $this->_root; $this->_contextualize($node); return $this->_states['current'] = $node->namespace = $node; }
php
protected function _namespaceNode() { $this->_codeNode(); $this->_flushUses(); $body = $this->_stream->current(); $name = $this->_stream->next([';', '{']); $this->_states['body'] .= $body; $node = new BlockDef($body . $name, 'namespace'); $node->hasMethods = false; $node->name = trim(substr($name, 0, -1)); $this->_states['current'] = $this->_root; $this->_contextualize($node); return $this->_states['current'] = $node->namespace = $node; }
[ "protected", "function", "_namespaceNode", "(", ")", "{", "$", "this", "->", "_codeNode", "(", ")", ";", "$", "this", "->", "_flushUses", "(", ")", ";", "$", "body", "=", "$", "this", "->", "_stream", "->", "current", "(", ")", ";", "$", "name", "=...
Build a namespace node.
[ "Build", "a", "namespace", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L329-L342
train
kahlan/kahlan
src/Jit/Parser.php
Parser._flushUses
protected function _flushUses() { if ($this->_states['current'] && $this->_states['current']->namespace) { $this->_states['current']->namespace->uses = $this->_states['uses']; $this->_states['uses'] = []; } }
php
protected function _flushUses() { if ($this->_states['current'] && $this->_states['current']->namespace) { $this->_states['current']->namespace->uses = $this->_states['uses']; $this->_states['uses'] = []; } }
[ "protected", "function", "_flushUses", "(", ")", "{", "if", "(", "$", "this", "->", "_states", "[", "'current'", "]", "&&", "$", "this", "->", "_states", "[", "'current'", "]", "->", "namespace", ")", "{", "$", "this", "->", "_states", "[", "'current'"...
Attache the founded uses to the current namespace.
[ "Attache", "the", "founded", "uses", "to", "the", "current", "namespace", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L347-L353
train
kahlan/kahlan
src/Jit/Parser.php
Parser._traitNode
protected function _traitNode() { $this->_codeNode(); $token = $this->_stream->current(true); $body = $token[1]; $body .= $this->_stream->skipWhitespaces(); $body .= $name = $this->_stream->current(); $body .= $this->_stream->next([';', '{']); $this->_states['body'] .= $body; $node = new BlockDef($body, 'trait'); $node->name = $name; return $this->_states['current'] = $this->_contextualize($node); }
php
protected function _traitNode() { $this->_codeNode(); $token = $this->_stream->current(true); $body = $token[1]; $body .= $this->_stream->skipWhitespaces(); $body .= $name = $this->_stream->current(); $body .= $this->_stream->next([';', '{']); $this->_states['body'] .= $body; $node = new BlockDef($body, 'trait'); $node->name = $name; return $this->_states['current'] = $this->_contextualize($node); }
[ "protected", "function", "_traitNode", "(", ")", "{", "$", "this", "->", "_codeNode", "(", ")", ";", "$", "token", "=", "$", "this", "->", "_stream", "->", "current", "(", "true", ")", ";", "$", "body", "=", "$", "token", "[", "1", "]", ";", "$",...
Build a trait node.
[ "Build", "a", "trait", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L358-L371
train
kahlan/kahlan
src/Jit/Parser.php
Parser._classNode
protected function _classNode() { if (substr($this->_states['body'], -2) === '::') { // Bails out on `::class` $this->_states['body'] .= 'class'; return; } $this->_codeNode(); $token = $this->_stream->current(true); $body = $token[1]; $body .= $this->_stream->skipWhitespaces(); $body .= $name = $this->_stream->current(); if ($name !== '{') { $body .= $this->_stream->next(['{', T_EXTENDS, T_IMPLEMENTS]); } else { $name = ''; } $token = $this->_stream->current(true); $extends = ''; $implements = ''; if ($token[0] === T_EXTENDS) { $body .= $this->_stream->skipWhitespaces(); $body .= $extends = $this->_stream->skipWhile([T_STRING, T_NS_SEPARATOR]); $body .= $this->_stream->current(); if ($this->_stream->current() !== '{') { $body .= $this->_stream->next('{'); } } elseif ($token[0] === T_IMPLEMENTS) { $body .= $implements = $this->_stream->next('{'); $implements = substr($implements, 0, -1); } $node = new BlockDef($body, 'class'); $node->name = $name; $node->extends = $this->_normalizeClass($extends); $node->implements = $this->_normalizeImplements($implements); $this->_states['body'] .= $body; return $this->_states['current'] = $this->_contextualize($node); }
php
protected function _classNode() { if (substr($this->_states['body'], -2) === '::') { // Bails out on `::class` $this->_states['body'] .= 'class'; return; } $this->_codeNode(); $token = $this->_stream->current(true); $body = $token[1]; $body .= $this->_stream->skipWhitespaces(); $body .= $name = $this->_stream->current(); if ($name !== '{') { $body .= $this->_stream->next(['{', T_EXTENDS, T_IMPLEMENTS]); } else { $name = ''; } $token = $this->_stream->current(true); $extends = ''; $implements = ''; if ($token[0] === T_EXTENDS) { $body .= $this->_stream->skipWhitespaces(); $body .= $extends = $this->_stream->skipWhile([T_STRING, T_NS_SEPARATOR]); $body .= $this->_stream->current(); if ($this->_stream->current() !== '{') { $body .= $this->_stream->next('{'); } } elseif ($token[0] === T_IMPLEMENTS) { $body .= $implements = $this->_stream->next('{'); $implements = substr($implements, 0, -1); } $node = new BlockDef($body, 'class'); $node->name = $name; $node->extends = $this->_normalizeClass($extends); $node->implements = $this->_normalizeImplements($implements); $this->_states['body'] .= $body; return $this->_states['current'] = $this->_contextualize($node); }
[ "protected", "function", "_classNode", "(", ")", "{", "if", "(", "substr", "(", "$", "this", "->", "_states", "[", "'body'", "]", ",", "-", "2", ")", "===", "'::'", ")", "{", "// Bails out on `::class`", "$", "this", "->", "_states", "[", "'body'", "]"...
Build a class node.
[ "Build", "a", "class", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L393-L431
train
kahlan/kahlan
src/Jit/Parser.php
Parser._normalizeClass
protected function _normalizeClass($name) { if (!$name || $name[0] === '\\') { return $name; } if ($this->_states['uses']) { $tokens = explode('\\', $name, 2); if (isset($this->_states['uses'][$tokens[0]])) { $prefix = $this->_states['uses'][$tokens[0]]; return count($tokens) === 2 ? '\\' . $prefix . '\\' . $tokens[1] : '\\' . $prefix; } } $current = $this->_states['current']; $prefix = '\\'; if ($current->namespace) { $prefix .= $current->namespace->name . '\\'; } return $prefix . $name; }
php
protected function _normalizeClass($name) { if (!$name || $name[0] === '\\') { return $name; } if ($this->_states['uses']) { $tokens = explode('\\', $name, 2); if (isset($this->_states['uses'][$tokens[0]])) { $prefix = $this->_states['uses'][$tokens[0]]; return count($tokens) === 2 ? '\\' . $prefix . '\\' . $tokens[1] : '\\' . $prefix; } } $current = $this->_states['current']; $prefix = '\\'; if ($current->namespace) { $prefix .= $current->namespace->name . '\\'; } return $prefix . $name; }
[ "protected", "function", "_normalizeClass", "(", "$", "name", ")", "{", "if", "(", "!", "$", "name", "||", "$", "name", "[", "0", "]", "===", "'\\\\'", ")", "{", "return", "$", "name", ";", "}", "if", "(", "$", "this", "->", "_states", "[", "'use...
Normalizes a class name. @param string $name A class name value. @return string The fully namespaced class extends value.
[ "Normalizes", "a", "class", "name", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L439-L457
train
kahlan/kahlan
src/Jit/Parser.php
Parser._codeNode
protected function _codeNode($type = null, $coverable = false) { $body = $this->_states['body']; if ($body === '') { return; } $node = new NodeDef($body, $type ?: $this->_codeType()); return $this->_contextualize($node, $coverable); }
php
protected function _codeNode($type = null, $coverable = false) { $body = $this->_states['body']; if ($body === '') { return; } $node = new NodeDef($body, $type ?: $this->_codeType()); return $this->_contextualize($node, $coverable); }
[ "protected", "function", "_codeNode", "(", "$", "type", "=", "null", ",", "$", "coverable", "=", "false", ")", "{", "$", "body", "=", "$", "this", "->", "_states", "[", "'body'", "]", ";", "if", "(", "$", "body", "===", "''", ")", "{", "return", ...
Build a code node.
[ "Build", "a", "code", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L571-L580
train
kahlan/kahlan
src/Jit/Parser.php
Parser._stringNode
protected function _stringNode($delimiter = '', $heredoc = false) { $this->_codeNode(); $token = $this->_stream->current(true); if (!$delimiter) { $this->_states['body'] = $token[1]; } elseif ($delimiter === '"') { $this->_states['body'] = $token[1] . $this->_stream->next('"'); } else { $this->_states['body'] = $token[1] . $this->_stream->nextSequence($delimiter); } if ($heredoc) { $this->_states['body'] .= $this->_stream->next([';']); } $node = new NodeDef($this->_states['body'], 'string'); $this->_contextualize($node); return $node; }
php
protected function _stringNode($delimiter = '', $heredoc = false) { $this->_codeNode(); $token = $this->_stream->current(true); if (!$delimiter) { $this->_states['body'] = $token[1]; } elseif ($delimiter === '"') { $this->_states['body'] = $token[1] . $this->_stream->next('"'); } else { $this->_states['body'] = $token[1] . $this->_stream->nextSequence($delimiter); } if ($heredoc) { $this->_states['body'] .= $this->_stream->next([';']); } $node = new NodeDef($this->_states['body'], 'string'); $this->_contextualize($node); return $node; }
[ "protected", "function", "_stringNode", "(", "$", "delimiter", "=", "''", ",", "$", "heredoc", "=", "false", ")", "{", "$", "this", "->", "_codeNode", "(", ")", ";", "$", "token", "=", "$", "this", "->", "_stream", "->", "current", "(", "true", ")", ...
Build a string node.
[ "Build", "a", "string", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L598-L616
train
kahlan/kahlan
src/Jit/Parser.php
Parser._commentNode
protected function _commentNode() { $this->_codeNode(); $token = $this->_stream->current(true); $this->_states['body'] = $token[1]; $node = new NodeDef($this->_states['body'], 'comment'); return $this->_contextualize($node); }
php
protected function _commentNode() { $this->_codeNode(); $token = $this->_stream->current(true); $this->_states['body'] = $token[1]; $node = new NodeDef($this->_states['body'], 'comment'); return $this->_contextualize($node); }
[ "protected", "function", "_commentNode", "(", ")", "{", "$", "this", "->", "_codeNode", "(", ")", ";", "$", "token", "=", "$", "this", "->", "_stream", "->", "current", "(", "true", ")", ";", "$", "this", "->", "_states", "[", "'body'", "]", "=", "...
Build a comment node.
[ "Build", "a", "comment", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L621-L628
train
kahlan/kahlan
src/Jit/Parser.php
Parser._contextualize
protected function _contextualize($node, $coverable = false) { $parent = $this->_states['current']; $node->namespace = $parent->namespace; $node->function = $parent->function; $node->parent = $parent; $node->coverable = $parent->hasMethods ? false : $coverable; $parent->tree[] = $node; $this->_assignLines($node); $node->inPhp = $this->_states['php']; $this->_states['body'] = ''; return $node; }
php
protected function _contextualize($node, $coverable = false) { $parent = $this->_states['current']; $node->namespace = $parent->namespace; $node->function = $parent->function; $node->parent = $parent; $node->coverable = $parent->hasMethods ? false : $coverable; $parent->tree[] = $node; $this->_assignLines($node); $node->inPhp = $this->_states['php']; $this->_states['body'] = ''; return $node; }
[ "protected", "function", "_contextualize", "(", "$", "node", ",", "$", "coverable", "=", "false", ")", "{", "$", "parent", "=", "$", "this", "->", "_states", "[", "'current'", "]", ";", "$", "node", "->", "namespace", "=", "$", "parent", "->", "namespa...
Contextualize a node.
[ "Contextualize", "a", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L633-L646
train
kahlan/kahlan
src/Jit/Parser.php
Parser._initLines
protected function _initLines($content) { if (!$this->_states['lines']) { return; } $lines = explode("\n", $content); $nbLines = count($lines); if ($this->_states['lines']) { for ($i = 0; $i < $nbLines; $i++) { $this->_root->lines['content'][$i] = [ 'body' => $lines[$i], 'nodes' => [], 'coverable' => false ]; } } }
php
protected function _initLines($content) { if (!$this->_states['lines']) { return; } $lines = explode("\n", $content); $nbLines = count($lines); if ($this->_states['lines']) { for ($i = 0; $i < $nbLines; $i++) { $this->_root->lines['content'][$i] = [ 'body' => $lines[$i], 'nodes' => [], 'coverable' => false ]; } } }
[ "protected", "function", "_initLines", "(", "$", "content", ")", "{", "if", "(", "!", "$", "this", "->", "_states", "[", "'lines'", "]", ")", "{", "return", ";", "}", "$", "lines", "=", "explode", "(", "\"\\n\"", ",", "$", "content", ")", ";", "$",...
Adds lines stores for root node. @param string $content A php file content.
[ "Adds", "lines", "stores", "for", "root", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L653-L669
train
kahlan/kahlan
src/Jit/Parser.php
Parser._assignLines
protected function _assignLines($node) { if (!$this->_states['lines']) { return; } $body = $node->body; $num = $this->_states['num']; $lines = explode("\n", $body); $nb = count($lines) - 1; $this->_states['num'] += $nb; foreach ($lines as $i => $line) { $this->_assignLine($num + $i, $node, $line); } $node->parent->lines['stop'] = $this->_states['num'] - (trim($lines[$nb]) ? 0 : 1); }
php
protected function _assignLines($node) { if (!$this->_states['lines']) { return; } $body = $node->body; $num = $this->_states['num']; $lines = explode("\n", $body); $nb = count($lines) - 1; $this->_states['num'] += $nb; foreach ($lines as $i => $line) { $this->_assignLine($num + $i, $node, $line); } $node->parent->lines['stop'] = $this->_states['num'] - (trim($lines[$nb]) ? 0 : 1); }
[ "protected", "function", "_assignLines", "(", "$", "node", ")", "{", "if", "(", "!", "$", "this", "->", "_states", "[", "'lines'", "]", ")", "{", "return", ";", "}", "$", "body", "=", "$", "node", "->", "body", ";", "$", "num", "=", "$", "this", ...
Assign the node to some lines and makes them availaible at the root node. @param object $node The node to match. @param string $body The to match.
[ "Assign", "the", "node", "to", "some", "lines", "and", "makes", "them", "availaible", "at", "the", "root", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L677-L694
train
kahlan/kahlan
src/Jit/Parser.php
Parser._assignLine
protected function _assignLine($index, $node, $line) { if ($node->lines['start'] === null) { $node->lines['start'] = $index; } $node->lines['stop'] = $index; if (trim($line)) { $this->_root->lines['content'][$index]['nodes'][] = $node; } }
php
protected function _assignLine($index, $node, $line) { if ($node->lines['start'] === null) { $node->lines['start'] = $index; } $node->lines['stop'] = $index; if (trim($line)) { $this->_root->lines['content'][$index]['nodes'][] = $node; } }
[ "protected", "function", "_assignLine", "(", "$", "index", ",", "$", "node", ",", "$", "line", ")", "{", "if", "(", "$", "node", "->", "lines", "[", "'start'", "]", "===", "null", ")", "{", "$", "node", "->", "lines", "[", "'start'", "]", "=", "$...
Assign a node to a specific line. @param object $node The node to match. @param string $body The to match.
[ "Assign", "a", "node", "to", "a", "specific", "line", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L702-L711
train
kahlan/kahlan
src/Jit/Parser.php
Parser._assignCoverable
protected function _assignCoverable() { if (!$this->_states['lines']) { return; } foreach ($this->_root->lines['content'] as $index => $value) { $this->_root->lines['content'][$index]['coverable'] = $this->_isCoverable($index); } }
php
protected function _assignCoverable() { if (!$this->_states['lines']) { return; } foreach ($this->_root->lines['content'] as $index => $value) { $this->_root->lines['content'][$index]['coverable'] = $this->_isCoverable($index); } }
[ "protected", "function", "_assignCoverable", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_states", "[", "'lines'", "]", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "_root", "->", "lines", "[", "'content'", "]", "as", "$", ...
Assign coverable data to lines.
[ "Assign", "coverable", "data", "to", "lines", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L716-L725
train
kahlan/kahlan
src/Jit/Parser.php
Parser._isCoverable
protected function _isCoverable($index) { $coverable = false; foreach ($this->_root->lines['content'][$index]['nodes'] as $node) { if ($node->coverable && ($node->lines['stop'] === $index)) { $coverable = true; } } return $coverable; }
php
protected function _isCoverable($index) { $coverable = false; foreach ($this->_root->lines['content'][$index]['nodes'] as $node) { if ($node->coverable && ($node->lines['stop'] === $index)) { $coverable = true; } } return $coverable; }
[ "protected", "function", "_isCoverable", "(", "$", "index", ")", "{", "$", "coverable", "=", "false", ";", "foreach", "(", "$", "this", "->", "_root", "->", "lines", "[", "'content'", "]", "[", "$", "index", "]", "[", "'nodes'", "]", "as", "$", "node...
Checks if a specific line is coverable. @param integer $index The line to check. @return boolean
[ "Checks", "if", "a", "specific", "line", "is", "coverable", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L733-L742
train
kahlan/kahlan
src/Jit/Parser.php
Parser.debug
public static function debug($content) { $root = is_object($content) ? $content : static::parse($content, ['lines' => true]); $result = ''; $abbr = [ 'file' => 'file', 'open' => 'open', 'close' => 'close', 'declare' => 'declare', 'namespace' => 'namespace', 'use' => 'use', 'class' => 'class', 'interface' => 'interface', 'trait' => 'trait', 'function' => 'function', 'signature' => 'signature', 'attribute' => 'a', 'code' => 'c', 'comment' => 'd', 'plain' => 'p', 'string' => 's' ]; foreach ($root->lines['content'] as $num => $content) { $start = $stop = $line = $num + 1; $result .= '#' . str_pad($line, 6, ' '); $types = []; foreach ($content['nodes'] as $node) { $types[] = $abbr[$node->type]; $stop = max($stop, $node->lines['stop'] + 1); } $result .= $content['coverable'] ? '*' : ' '; $result .= '[' . str_pad(join(',', $types), 19, ' ', STR_PAD_BOTH) . "]"; $result .= ' ' . str_pad("#{$start} > #{$stop}", 16, ' ') . "|"; $result .= $content['body'] . "\n"; } return $result; }
php
public static function debug($content) { $root = is_object($content) ? $content : static::parse($content, ['lines' => true]); $result = ''; $abbr = [ 'file' => 'file', 'open' => 'open', 'close' => 'close', 'declare' => 'declare', 'namespace' => 'namespace', 'use' => 'use', 'class' => 'class', 'interface' => 'interface', 'trait' => 'trait', 'function' => 'function', 'signature' => 'signature', 'attribute' => 'a', 'code' => 'c', 'comment' => 'd', 'plain' => 'p', 'string' => 's' ]; foreach ($root->lines['content'] as $num => $content) { $start = $stop = $line = $num + 1; $result .= '#' . str_pad($line, 6, ' '); $types = []; foreach ($content['nodes'] as $node) { $types[] = $abbr[$node->type]; $stop = max($stop, $node->lines['stop'] + 1); } $result .= $content['coverable'] ? '*' : ' '; $result .= '[' . str_pad(join(',', $types), 19, ' ', STR_PAD_BOTH) . "]"; $result .= ' ' . str_pad("#{$start} > #{$stop}", 16, ' ') . "|"; $result .= $content['body'] . "\n"; } return $result; }
[ "public", "static", "function", "debug", "(", "$", "content", ")", "{", "$", "root", "=", "is_object", "(", "$", "content", ")", "?", "$", "content", ":", "static", "::", "parse", "(", "$", "content", ",", "[", "'lines'", "=>", "true", "]", ")", ";...
Returns a reader-friendly output for debug purpose. @param mixed A node or a php string to parse. @return string the unparsed file.
[ "Returns", "a", "reader", "-", "friendly", "output", "for", "debug", "purpose", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Parser.php#L774-L812
train
kahlan/kahlan
src/Dir/Dir.php
Dir.scan
public static function scan($path, $options = []) { $defaults = [ 'iterator' => RecursiveIteratorIterator::SELF_FIRST, 'skipDots' => true, 'leavesOnly' => false, 'followSymlinks' => true, 'recursive' => true ]; $options += $defaults; $paths = (array) $path; $dirFlags = static::_dirFlags($options); $iteratorFlags = static::_iteratorFlags($options); $result = []; foreach ($paths as $path) { $result = array_merge($result, static::_scan($path, $options, $dirFlags, $iteratorFlags)); } return $result; }
php
public static function scan($path, $options = []) { $defaults = [ 'iterator' => RecursiveIteratorIterator::SELF_FIRST, 'skipDots' => true, 'leavesOnly' => false, 'followSymlinks' => true, 'recursive' => true ]; $options += $defaults; $paths = (array) $path; $dirFlags = static::_dirFlags($options); $iteratorFlags = static::_iteratorFlags($options); $result = []; foreach ($paths as $path) { $result = array_merge($result, static::_scan($path, $options, $dirFlags, $iteratorFlags)); } return $result; }
[ "public", "static", "function", "scan", "(", "$", "path", ",", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'iterator'", "=>", "RecursiveIteratorIterator", "::", "SELF_FIRST", ",", "'skipDots'", "=>", "true", ",", "'leavesOnly'", "=...
Scans one or many directories for files. @param array|string $path Path or paths to scan. @param array $options Scanning options. Possible values are: -`'iterator'` _integer_ : The iterator mode. -`'skipDots'` _boolean_ : Keeps '.' and '..' if `true`. -`'leavesOnly'` _boolean_ : Keeps only leaves if `true`. -`'followSymlinks'` _boolean_ : Follows Symlinks if `true`. -`'recursive'` _boolean_ : Scans recursively if `true`. -`'include'` _string|array_: An array of includes. -`'exclude'` _string|array_: An array of excludes. -`'type'` _string|array_: An array of types. @return array @throws Exception
[ "Scans", "one", "or", "many", "directories", "for", "files", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L48-L69
train
kahlan/kahlan
src/Dir/Dir.php
Dir._scan
protected static function _scan($path, $options, $dirFlags, $iteratorFlags) { if (!file_exists($path)) { throw new Exception("Unexisting path `{$path}`."); } if (!is_dir($path)) { return [$path]; } $worker = new RecursiveDirectoryIterator($path, $dirFlags); if ($options['recursive']) { $worker = new RecursiveIteratorIterator($worker, $iteratorFlags); } $filter = new static($worker); $filter->filter($options); $result = []; foreach ($filter as $key => $value) { $result[] = $key; } return $result; }
php
protected static function _scan($path, $options, $dirFlags, $iteratorFlags) { if (!file_exists($path)) { throw new Exception("Unexisting path `{$path}`."); } if (!is_dir($path)) { return [$path]; } $worker = new RecursiveDirectoryIterator($path, $dirFlags); if ($options['recursive']) { $worker = new RecursiveIteratorIterator($worker, $iteratorFlags); } $filter = new static($worker); $filter->filter($options); $result = []; foreach ($filter as $key => $value) { $result[] = $key; } return $result; }
[ "protected", "static", "function", "_scan", "(", "$", "path", ",", "$", "options", ",", "$", "dirFlags", ",", "$", "iteratorFlags", ")", "{", "if", "(", "!", "file_exists", "(", "$", "path", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unexistin...
Scans a given directory for files. @param string $path Path or paths to scan. @param array $options Scanning options. Possible values are: -`'iterator'` _integer_ : The iterator mode. -`'skipDots'` _boolean_ : Keeps '.' and '..' if `true`. -`'leavesOnly'` _boolean_ : Keeps only leaves if `true`. -`'followSymlinks'` _boolean_ : Follows Symlinks if `true`. -`'recursive'` _boolean_ : Scans recursively if `true`. -`'include'` _string|array_: An array of includes. -`'exclude'` _string|array_: An array of excludes. -`'type'` _string|array_: An array of types. @return array
[ "Scans", "a", "given", "directory", "for", "files", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L86-L106
train
kahlan/kahlan
src/Dir/Dir.php
Dir._dirFlags
public static function _dirFlags($options) { $flag = $options['followSymlinks'] ? FilesystemIterator::FOLLOW_SYMLINKS : 0; $flag |= $options['skipDots'] ? FilesystemIterator::SKIP_DOTS : 0; $flag |= FilesystemIterator::UNIX_PATHS; return $flag; }
php
public static function _dirFlags($options) { $flag = $options['followSymlinks'] ? FilesystemIterator::FOLLOW_SYMLINKS : 0; $flag |= $options['skipDots'] ? FilesystemIterator::SKIP_DOTS : 0; $flag |= FilesystemIterator::UNIX_PATHS; return $flag; }
[ "public", "static", "function", "_dirFlags", "(", "$", "options", ")", "{", "$", "flag", "=", "$", "options", "[", "'followSymlinks'", "]", "?", "FilesystemIterator", "::", "FOLLOW_SYMLINKS", ":", "0", ";", "$", "flag", "|=", "$", "options", "[", "'skipDot...
Returns `FilesystemIterator` flags from `Dir` options. @param array $options Scanning options. Possible values are: -`'skipDots'` _boolean_ : Keeps '.' and '..' if `true`. -`'followSymlinks'` _boolean_ : Follows Symlinks if `true`. @return integer Some `FilesystemIterator` flags
[ "Returns", "FilesystemIterator", "flags", "from", "Dir", "options", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L130-L136
train
kahlan/kahlan
src/Dir/Dir.php
Dir.tempnam
public static function tempnam($path = null, $prefix = '') { if ($path === null) { $path = sys_get_temp_dir(); } if ($tempfile = tempnam($path, $prefix)) { unlink($tempfile); mkdir($tempfile); } return $tempfile; }
php
public static function tempnam($path = null, $prefix = '') { if ($path === null) { $path = sys_get_temp_dir(); } if ($tempfile = tempnam($path, $prefix)) { unlink($tempfile); mkdir($tempfile); } return $tempfile; }
[ "public", "static", "function", "tempnam", "(", "$", "path", "=", "null", ",", "$", "prefix", "=", "''", ")", "{", "if", "(", "$", "path", "===", "null", ")", "{", "$", "path", "=", "sys_get_temp_dir", "(", ")", ";", "}", "if", "(", "$", "tempfil...
Creates a directory with unique file name. @see http://php.net/manual/en/function.tempnam.php @param string $path The directory where the temporary filename will be created. @param string $prefix The prefix of the generated temporary filename. @return string
[ "Creates", "a", "directory", "with", "unique", "file", "name", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L282-L294
train
kahlan/kahlan
src/Dir/Dir.php
Dir.filter
public function filter($options = []) { $defaults = array( 'include' => ['*'], 'exclude' => [], 'type' => [] ); $options += $defaults; $this->_exclude = (array) $options['exclude']; $this->_include = (array) $options['include']; $this->_types = (array) $options['type']; }
php
public function filter($options = []) { $defaults = array( 'include' => ['*'], 'exclude' => [], 'type' => [] ); $options += $defaults; $this->_exclude = (array) $options['exclude']; $this->_include = (array) $options['include']; $this->_types = (array) $options['type']; }
[ "public", "function", "filter", "(", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "array", "(", "'include'", "=>", "[", "'*'", "]", ",", "'exclude'", "=>", "[", "]", ",", "'type'", "=>", "[", "]", ")", ";", "$", "options", "+=",...
Applies some filters to a `FilterIterator` instance. @param array $options The filters optoins. Possible values are: -`'include'` _string|array_: An array of includes. -`'exclude'` _string|array_: An array of excludes. -`'type'` _string|array_: An array of types.
[ "Applies", "some", "filters", "to", "a", "FilterIterator", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L304-L315
train
kahlan/kahlan
src/Dir/Dir.php
Dir.accept
public function accept() { $path = $this->current()->getPathname(); if ($this->_excluded($path)) { return false; } if (!$this->_included($path)) { return false; } return $this->_matchType(); }
php
public function accept() { $path = $this->current()->getPathname(); if ($this->_excluded($path)) { return false; } if (!$this->_included($path)) { return false; } return $this->_matchType(); }
[ "public", "function", "accept", "(", ")", "{", "$", "path", "=", "$", "this", "->", "current", "(", ")", "->", "getPathname", "(", ")", ";", "if", "(", "$", "this", "->", "_excluded", "(", "$", "path", ")", ")", "{", "return", "false", ";", "}", ...
Checks if a file passes the setted filters. @return boolean
[ "Checks", "if", "a", "file", "passes", "the", "setted", "filters", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L322-L332
train
kahlan/kahlan
src/Dir/Dir.php
Dir._excluded
protected function _excluded($path) { foreach ($this->_exclude as $exclude) { if (fnmatch($exclude, $path)) { return true; } } return false; }
php
protected function _excluded($path) { foreach ($this->_exclude as $exclude) { if (fnmatch($exclude, $path)) { return true; } } return false; }
[ "protected", "function", "_excluded", "(", "$", "path", ")", "{", "foreach", "(", "$", "this", "->", "_exclude", "as", "$", "exclude", ")", "{", "if", "(", "fnmatch", "(", "$", "exclude", ",", "$", "path", ")", ")", "{", "return", "true", ";", "}",...
Checks if a file passes match an excluded path. @return boolean Returns `true` if match an excluded path, `false` otherwise.
[ "Checks", "if", "a", "file", "passes", "match", "an", "excluded", "path", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L339-L347
train
kahlan/kahlan
src/Dir/Dir.php
Dir._matchType
protected function _matchType() { if (!$this->_types) { return true; } $file = $this->current(); foreach ($this->_types as $type) { $method = 'is' . ucfirst($type); if ($file->$method()) { return true; } } return false; }
php
protected function _matchType() { if (!$this->_types) { return true; } $file = $this->current(); foreach ($this->_types as $type) { $method = 'is' . ucfirst($type); if ($file->$method()) { return true; } } return false; }
[ "protected", "function", "_matchType", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_types", ")", "{", "return", "true", ";", "}", "$", "file", "=", "$", "this", "->", "current", "(", ")", ";", "foreach", "(", "$", "this", "->", "_types", "...
Checks if a file passes match the allowed type. @return boolean Returns `true` if match the allowed type, `false` otherwise.
[ "Checks", "if", "a", "file", "passes", "match", "the", "allowed", "type", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Dir/Dir.php#L369-L382
train
kahlan/kahlan
src/Block/Group.php
Group.stats
public function stats() { if ($this->_stats !== null) { return $this->_stats; } Suite::push($this); $builder = function ($block) { $block->load(); $normal = 0; $inactive = 0; $focused = 0; $excluded = 0; foreach ($block->children() as $child) { if ($block->excluded()) { $child->type('exclude'); } if ($child instanceof Group) { $result = $child->stats(); if ($child->focused() && !$result['focused']) { $focused += $result['normal']; $excluded += $result['excluded']; $child->broadcastFocus(); } elseif (!$child->enabled()) { $inactive += $result['normal']; $focused += $result['focused']; $excluded += $result['excluded']; } else { $normal += $result['normal']; $focused += $result['focused']; $excluded += $result['excluded']; } } else { switch ($child->type()) { case 'exclude': $excluded++; break; case 'focus': $focused++; break; default: $normal++; break; } } } return compact('normal', 'inactive', 'focused', 'excluded'); }; if (Suite::$PHP >= 7 && !defined('HHVM_VERSION')) { try { $stats = $builder($this); } catch (Throwable $exception) { $this->log()->type('errored'); $this->log()->exception($exception); $stats = [ 'normal' => 0, 'focused' => 0, 'excluded' => 0 ]; } } else { $stats = $builder($this); } Suite::pop(); return $stats; }
php
public function stats() { if ($this->_stats !== null) { return $this->_stats; } Suite::push($this); $builder = function ($block) { $block->load(); $normal = 0; $inactive = 0; $focused = 0; $excluded = 0; foreach ($block->children() as $child) { if ($block->excluded()) { $child->type('exclude'); } if ($child instanceof Group) { $result = $child->stats(); if ($child->focused() && !$result['focused']) { $focused += $result['normal']; $excluded += $result['excluded']; $child->broadcastFocus(); } elseif (!$child->enabled()) { $inactive += $result['normal']; $focused += $result['focused']; $excluded += $result['excluded']; } else { $normal += $result['normal']; $focused += $result['focused']; $excluded += $result['excluded']; } } else { switch ($child->type()) { case 'exclude': $excluded++; break; case 'focus': $focused++; break; default: $normal++; break; } } } return compact('normal', 'inactive', 'focused', 'excluded'); }; if (Suite::$PHP >= 7 && !defined('HHVM_VERSION')) { try { $stats = $builder($this); } catch (Throwable $exception) { $this->log()->type('errored'); $this->log()->exception($exception); $stats = [ 'normal' => 0, 'focused' => 0, 'excluded' => 0 ]; } } else { $stats = $builder($this); } Suite::pop(); return $stats; }
[ "public", "function", "stats", "(", ")", "{", "if", "(", "$", "this", "->", "_stats", "!==", "null", ")", "{", "return", "$", "this", "->", "_stats", ";", "}", "Suite", "::", "push", "(", "$", "this", ")", ";", "$", "builder", "=", "function", "(...
Builds the group stats. @return array The group stats.
[ "Builds", "the", "group", "stats", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Group.php#L81-L151
train
kahlan/kahlan
src/Block/Group.php
Group.partition
public function partition($index, $total) { $index = (integer) $index; $total = (integer) $total; if (!$index || !$total || $index > $total) { throw new Exception("Invalid partition parameters: {$index}/{$total}"); } $groups = []; $partitions = []; $partitionsTotal = []; for ($i = 0; $i < $total; $i++) { $partitions[$i] = []; $partitionsTotal[$i] = 0; } $children = $this->children(); foreach ($children as $key => $child) { $groups[$key] = $child->stats()['normal']; $child->enabled(false); } asort($groups); foreach ($groups as $key => $value) { $i = array_search(min($partitionsTotal), $partitionsTotal); $partitions[$i][] = $key; $partitionsTotal[$i] += $groups[$key]; } foreach ($partitions[$index - 1] as $key) { $children[$key]->enabled(true); } }
php
public function partition($index, $total) { $index = (integer) $index; $total = (integer) $total; if (!$index || !$total || $index > $total) { throw new Exception("Invalid partition parameters: {$index}/{$total}"); } $groups = []; $partitions = []; $partitionsTotal = []; for ($i = 0; $i < $total; $i++) { $partitions[$i] = []; $partitionsTotal[$i] = 0; } $children = $this->children(); foreach ($children as $key => $child) { $groups[$key] = $child->stats()['normal']; $child->enabled(false); } asort($groups); foreach ($groups as $key => $value) { $i = array_search(min($partitionsTotal), $partitionsTotal); $partitions[$i][] = $key; $partitionsTotal[$i] += $groups[$key]; } foreach ($partitions[$index - 1] as $key) { $children[$key]->enabled(true); } }
[ "public", "function", "partition", "(", "$", "index", ",", "$", "total", ")", "{", "$", "index", "=", "(", "integer", ")", "$", "index", ";", "$", "total", "=", "(", "integer", ")", "$", "total", ";", "if", "(", "!", "$", "index", "||", "!", "$...
Splits the specs in different partitions and only enable one. @param integer $index The partition index to enable. @param integer $total The total of partitions.
[ "Splits", "the", "specs", "in", "different", "partitions", "and", "only", "enable", "one", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Group.php#L159-L193
train
kahlan/kahlan
src/Block/Group.php
Group.load
public function load() { if ($this->_loaded) { return; } $this->_loaded = true; if (!$closure = $this->closure()) { return; } return $this->_suite->runBlock($this, $closure, 'group'); }
php
public function load() { if ($this->_loaded) { return; } $this->_loaded = true; if (!$closure = $this->closure()) { return; } return $this->_suite->runBlock($this, $closure, 'group'); }
[ "public", "function", "load", "(", ")", "{", "if", "(", "$", "this", "->", "_loaded", ")", "{", "return", ";", "}", "$", "this", "->", "_loaded", "=", "true", ";", "if", "(", "!", "$", "closure", "=", "$", "this", "->", "closure", "(", ")", ")"...
Load the group.
[ "Load", "the", "group", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Group.php#L317-L327
train
kahlan/kahlan
src/Block/Group.php
Group._execute
protected function _execute() { if (!$this->enabled() && !$this->focused()) { return; } foreach ($this->_children as $child) { if ($this->suite()->failfast()) { break; } $this->_passed = $child->process() && $this->_passed; } }
php
protected function _execute() { if (!$this->enabled() && !$this->focused()) { return; } foreach ($this->_children as $child) { if ($this->suite()->failfast()) { break; } $this->_passed = $child->process() && $this->_passed; } }
[ "protected", "function", "_execute", "(", ")", "{", "if", "(", "!", "$", "this", "->", "enabled", "(", ")", "&&", "!", "$", "this", "->", "focused", "(", ")", ")", "{", "return", ";", "}", "foreach", "(", "$", "this", "->", "_children", "as", "$"...
Group execution helper.
[ "Group", "execution", "helper", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Group.php#L332-L343
train
kahlan/kahlan
src/Block/Group.php
Group._blockEnd
protected function _blockEnd($runAfterAll = true) { if ($runAfterAll) { if (Suite::$PHP >= 7 && !defined('HHVM_VERSION')) { try { $this->runCallbacks('afterAll', false); } catch (Throwable $exception) { $this->_exception($exception); } } else { try { $this->runCallbacks('afterAll', false); } catch (Exception $exception) { $this->_exception($exception); } } } $this->suite()->autoclear(); $type = $this->log()->type(); if ($type === 'failed' || $type === 'errored') { $this->_passed = false; $this->suite()->failure(); $this->summary()->log($this->log()); } $this->report('suiteEnd', $this); }
php
protected function _blockEnd($runAfterAll = true) { if ($runAfterAll) { if (Suite::$PHP >= 7 && !defined('HHVM_VERSION')) { try { $this->runCallbacks('afterAll', false); } catch (Throwable $exception) { $this->_exception($exception); } } else { try { $this->runCallbacks('afterAll', false); } catch (Exception $exception) { $this->_exception($exception); } } } $this->suite()->autoclear(); $type = $this->log()->type(); if ($type === 'failed' || $type === 'errored') { $this->_passed = false; $this->suite()->failure(); $this->summary()->log($this->log()); } $this->report('suiteEnd', $this); }
[ "protected", "function", "_blockEnd", "(", "$", "runAfterAll", "=", "true", ")", "{", "if", "(", "$", "runAfterAll", ")", "{", "if", "(", "Suite", "::", "$", "PHP", ">=", "7", "&&", "!", "defined", "(", "'HHVM_VERSION'", ")", ")", "{", "try", "{", ...
End group block execution helper.
[ "End", "group", "block", "execution", "helper", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Group.php#L357-L385
train
kahlan/kahlan
src/Block/Group.php
Group.runCallbacks
public function runCallbacks($name, $recursive = true) { $instances = $recursive ? $this->parents(true) : [$this]; if (strncmp($name, 'after', 5) === 0) { $instances = array_reverse($instances); } foreach ($instances as $instance) { foreach ($instance->_callbacks[$name] as $closure) { $this->_suite->runBlock($this, $closure, $name); } } }
php
public function runCallbacks($name, $recursive = true) { $instances = $recursive ? $this->parents(true) : [$this]; if (strncmp($name, 'after', 5) === 0) { $instances = array_reverse($instances); } foreach ($instances as $instance) { foreach ($instance->_callbacks[$name] as $closure) { $this->_suite->runBlock($this, $closure, $name); } } }
[ "public", "function", "runCallbacks", "(", "$", "name", ",", "$", "recursive", "=", "true", ")", "{", "$", "instances", "=", "$", "recursive", "?", "$", "this", "->", "parents", "(", "true", ")", ":", "[", "$", "this", "]", ";", "if", "(", "strncmp...
Runs a callback. @param string $name The name of the callback (i.e `'beforeEach'` or `'afterEach'`).
[ "Runs", "a", "callback", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Group.php#L392-L403
train
kahlan/kahlan
src/Block/Group.php
Group.broadcastFocus
public function broadcastFocus() { foreach ($this->_children as $child) { if ($child->type() !== 'normal') { continue; } $child->type('focus'); if ($child instanceof Group) { $child->broadcastFocus(); } } }
php
public function broadcastFocus() { foreach ($this->_children as $child) { if ($child->type() !== 'normal') { continue; } $child->type('focus'); if ($child instanceof Group) { $child->broadcastFocus(); } } }
[ "public", "function", "broadcastFocus", "(", ")", "{", "foreach", "(", "$", "this", "->", "_children", "as", "$", "child", ")", "{", "if", "(", "$", "child", "->", "type", "(", ")", "!==", "'normal'", ")", "{", "continue", ";", "}", "$", "child", "...
Apply focus downward to the leaf.
[ "Apply", "focus", "downward", "to", "the", "leaf", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Group.php#L420-L431
train
kahlan/kahlan
src/Summary.php
Summary.expectation
public function expectation() { $total = 0; foreach ($this->_logs as $key => $value) { foreach ($value as $log) { $total += count($log->children()); } } return $total; }
php
public function expectation() { $total = 0; foreach ($this->_logs as $key => $value) { foreach ($value as $log) { $total += count($log->children()); } } return $total; }
[ "public", "function", "expectation", "(", ")", "{", "$", "total", "=", "0", ";", "foreach", "(", "$", "this", "->", "_logs", "as", "$", "key", "=>", "$", "value", ")", "{", "foreach", "(", "$", "value", "as", "$", "log", ")", "{", "$", "total", ...
Return the total number of expectations. @return integer
[ "Return", "the", "total", "number", "of", "expectations", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Summary.php#L46-L55
train
kahlan/kahlan
src/Summary.php
Summary.add
public function add($type, $value) { if (!isset($this->_data[$type])) { $this->_data[$type] = []; } $this->_data[$type][] = $value; return $this; }
php
public function add($type, $value) { if (!isset($this->_data[$type])) { $this->_data[$type] = []; } $this->_data[$type][] = $value; return $this; }
[ "public", "function", "add", "(", "$", "type", ",", "$", "value", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_data", "[", "$", "type", "]", ")", ")", "{", "$", "this", "->", "_data", "[", "$", "type", "]", "=", "[", "]", ";...
Add a data to a specific key. @param string $type The type of data. @param mixed $value The value to add. @return self
[ "Add", "a", "data", "to", "a", "specific", "key", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Summary.php#L84-L91
train
kahlan/kahlan
src/Summary.php
Summary.log
public function log($log) { $type = $log->type(); if (!isset($this->_logs[$type])) { $this->_logs[$type] = []; } $this->_logs[$type][] = $log; return $this; }
php
public function log($log) { $type = $log->type(); if (!isset($this->_logs[$type])) { $this->_logs[$type] = []; } $this->_logs[$type][] = $log; return $this; }
[ "public", "function", "log", "(", "$", "log", ")", "{", "$", "type", "=", "$", "log", "->", "type", "(", ")", ";", "if", "(", "!", "isset", "(", "$", "this", "->", "_logs", "[", "$", "type", "]", ")", ")", "{", "$", "this", "->", "_logs", "...
Ingest a log. @param array $log The log report. @return self
[ "Ingest", "a", "log", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Summary.php#L110-L118
train
kahlan/kahlan
src/Summary.php
Summary.logs
public function logs($type = null) { if (func_num_args()) { return isset($this->_logs[$type]) ? $this->_logs[$type] : []; } $logs = []; foreach ($this->_logs as $key => $value) { $logs = array_merge($logs, $value); } return $logs; }
php
public function logs($type = null) { if (func_num_args()) { return isset($this->_logs[$type]) ? $this->_logs[$type] : []; } $logs = []; foreach ($this->_logs as $key => $value) { $logs = array_merge($logs, $value); } return $logs; }
[ "public", "function", "logs", "(", "$", "type", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", ")", "{", "return", "isset", "(", "$", "this", "->", "_logs", "[", "$", "type", "]", ")", "?", "$", "this", "->", "_logs", "[", "$", "t...
Get log report @param string $type The type of data. @return array
[ "Get", "log", "report" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Summary.php#L126-L136
train
kahlan/kahlan
src/Reporter/Coverage.php
Coverage.metrics
public function metrics() { $this->_start = microtime(true); $result = $this->_collector->metrics(); $this->_time = microtime(true) - $this->_start; return $result; }
php
public function metrics() { $this->_start = microtime(true); $result = $this->_collector->metrics(); $this->_time = microtime(true) - $this->_start; return $result; }
[ "public", "function", "metrics", "(", ")", "{", "$", "this", "->", "_start", "=", "microtime", "(", "true", ")", ";", "$", "result", "=", "$", "this", "->", "_collector", "->", "metrics", "(", ")", ";", "$", "this", "->", "_time", "=", "microtime", ...
Gets the metrics about the coverage result.
[ "Gets", "the", "metrics", "about", "the", "coverage", "result", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage.php#L166-L172
train
kahlan/kahlan
src/Reporter/Coverage.php
Coverage._renderMetrics
protected function _renderMetrics($metrics, $verbosity) { $maxLabelWidth = null; if ($verbosity === 1) { return; } $metricsReport = $this->_getMetricsReport($metrics->children(), $verbosity, 0, 3, $maxLabelWidth); $name = $metrics->name() ?: '\\'; $maxLabelWidth = max(strlen($name) + 1, $maxLabelWidth); $maxLabelWidth += 4; $stats = $metrics->data(); $percent = number_format($stats['percent'], 2); $style = $this->_style($percent); $maxLineWidth = strlen($stats['lloc']); $this->write(str_repeat(' ', $maxLabelWidth)); $this->write(' '); $this->write(str_pad('Lines', $maxLineWidth * 2 + 3, ' ', STR_PAD_BOTH)); $this->write(str_pad('%', 12, ' ', STR_PAD_LEFT)); $this->write("\n\n"); $this->write(str_pad(' ' . $name, $maxLabelWidth)); $this->write(' '); $this->write(str_pad("{$stats['cloc']}", $maxLineWidth, ' ', STR_PAD_LEFT)); $this->write(' / '); $this->write(str_pad("{$stats['lloc']}", $maxLineWidth, ' ', STR_PAD_LEFT)); $this->write(' '); $this->write(str_pad("{$percent}%", 7, ' ', STR_PAD_LEFT), $style); $this->write("\n"); $this->_renderMetricsReport($metricsReport, $maxLabelWidth, $maxLineWidth, 0); }
php
protected function _renderMetrics($metrics, $verbosity) { $maxLabelWidth = null; if ($verbosity === 1) { return; } $metricsReport = $this->_getMetricsReport($metrics->children(), $verbosity, 0, 3, $maxLabelWidth); $name = $metrics->name() ?: '\\'; $maxLabelWidth = max(strlen($name) + 1, $maxLabelWidth); $maxLabelWidth += 4; $stats = $metrics->data(); $percent = number_format($stats['percent'], 2); $style = $this->_style($percent); $maxLineWidth = strlen($stats['lloc']); $this->write(str_repeat(' ', $maxLabelWidth)); $this->write(' '); $this->write(str_pad('Lines', $maxLineWidth * 2 + 3, ' ', STR_PAD_BOTH)); $this->write(str_pad('%', 12, ' ', STR_PAD_LEFT)); $this->write("\n\n"); $this->write(str_pad(' ' . $name, $maxLabelWidth)); $this->write(' '); $this->write(str_pad("{$stats['cloc']}", $maxLineWidth, ' ', STR_PAD_LEFT)); $this->write(' / '); $this->write(str_pad("{$stats['lloc']}", $maxLineWidth, ' ', STR_PAD_LEFT)); $this->write(' '); $this->write(str_pad("{$percent}%", 7, ' ', STR_PAD_LEFT), $style); $this->write("\n"); $this->_renderMetricsReport($metricsReport, $maxLabelWidth, $maxLineWidth, 0); }
[ "protected", "function", "_renderMetrics", "(", "$", "metrics", ",", "$", "verbosity", ")", "{", "$", "maxLabelWidth", "=", "null", ";", "if", "(", "$", "verbosity", "===", "1", ")", "{", "return", ";", "}", "$", "metricsReport", "=", "$", "this", "->"...
Outputs some metrics info where the metric is not the total coverage. @param Metrics $metrics A metrics instance. @param mixed $verbosity The options for the reporter, the options are: - `'verbosity`' _integer|string_: The verbosity level: - 1 : overall coverage value for the whole code. - 2 : overall coverage by namespaces. - 3 : overall coverage by classes. - 4 : overall coverage by methods and functions. - string : coverage for a fully namespaced (class/method/namespace) string.
[ "Outputs", "some", "metrics", "info", "where", "the", "metric", "is", "not", "the", "total", "coverage", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage.php#L186-L215
train
kahlan/kahlan
src/Reporter/Coverage.php
Coverage._getMetricsReport
protected function _getMetricsReport($children, $verbosity, $depth = 0, $tab = 3, &$maxWidth = null) { $list = []; foreach ($children as $child) { $type = $child->type(); if ($verbosity === 2 && $type !== 'namespace') { continue; } if ($verbosity === 3 && ($type === 'function' || $type === 'method')) { continue; } $name = $child->name(); if ($name !== '\\') { $pos = strrpos($name, '\\', $type === 'namespace' ? - 2 : 0); $basename = substr($name, $pos !== false ? $pos + 1 : 0); } else { $basename = '\\'; } $len = strlen($basename) + ($depth + 1) * $tab; if ($len > $maxWidth) { $maxWidth = $len; } $list[$basename] = [ 'metrics' => $child, 'children' => $this->_getMetricsReport($child->children(), $verbosity, $depth + 1, $tab, $maxWidth) ]; } return $list; }
php
protected function _getMetricsReport($children, $verbosity, $depth = 0, $tab = 3, &$maxWidth = null) { $list = []; foreach ($children as $child) { $type = $child->type(); if ($verbosity === 2 && $type !== 'namespace') { continue; } if ($verbosity === 3 && ($type === 'function' || $type === 'method')) { continue; } $name = $child->name(); if ($name !== '\\') { $pos = strrpos($name, '\\', $type === 'namespace' ? - 2 : 0); $basename = substr($name, $pos !== false ? $pos + 1 : 0); } else { $basename = '\\'; } $len = strlen($basename) + ($depth + 1) * $tab; if ($len > $maxWidth) { $maxWidth = $len; } $list[$basename] = [ 'metrics' => $child, 'children' => $this->_getMetricsReport($child->children(), $verbosity, $depth + 1, $tab, $maxWidth) ]; } return $list; }
[ "protected", "function", "_getMetricsReport", "(", "$", "children", ",", "$", "verbosity", ",", "$", "depth", "=", "0", ",", "$", "tab", "=", "3", ",", "&", "$", "maxWidth", "=", "null", ")", "{", "$", "list", "=", "[", "]", ";", "foreach", "(", ...
Extract some metrics reports to display according to a verbosity parameter. @param array $children A array of metrics. @param mixed $verbosity The options for the reporter, the options are: - `'verbosity`' _integer|string_: The verbosity level: - 1 : overall coverage value for the whole code. - 2 : overall coverage by namespaces. - 3 : overall coverage by classes. - 4 : overall coverage by methods and functions. - string : coverage for a fully namespaced (class/method/namespace) string. @param integer $depth The actual depth in the reporting. @param integer $tab The size of the tab used for lablels. @param integer $maxWidth Will contain the maximum width obtained for labels. @return array
[ "Extract", "some", "metrics", "reports", "to", "display", "according", "to", "a", "verbosity", "parameter", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage.php#L285-L317
train
kahlan/kahlan
src/Reporter/Coverage.php
Coverage._renderCoverage
protected function _renderCoverage($metrics) { $stats = $metrics->data(); foreach ($stats['files'] as $file) { $this->write("File: {$file}" . "\n\n"); $lines = file($file); $coverage = $this->_collector->export($file); if (isset($stats['line'])) { $start = $stats['line']['start']; $stop = $stats['line']['stop']; } else { $start = 0; $stop = count($lines) - 1; } for ($i = $start; $i <= $stop; $i++) { $value = isset($coverage[$i]) ? $coverage[$i] : null; $line = str_pad($i + 1, 6, ' ', STR_PAD_LEFT); $line .= ':' . str_pad($value, 6, ' '); $line .= $lines[$i]; if ($value) { $this->write($line, 'n;green'); } elseif ($value === 0) { $this->write($line, 'n;red'); } else { $this->write($line); } } $this->write("\n\n"); } }
php
protected function _renderCoverage($metrics) { $stats = $metrics->data(); foreach ($stats['files'] as $file) { $this->write("File: {$file}" . "\n\n"); $lines = file($file); $coverage = $this->_collector->export($file); if (isset($stats['line'])) { $start = $stats['line']['start']; $stop = $stats['line']['stop']; } else { $start = 0; $stop = count($lines) - 1; } for ($i = $start; $i <= $stop; $i++) { $value = isset($coverage[$i]) ? $coverage[$i] : null; $line = str_pad($i + 1, 6, ' ', STR_PAD_LEFT); $line .= ':' . str_pad($value, 6, ' '); $line .= $lines[$i]; if ($value) { $this->write($line, 'n;green'); } elseif ($value === 0) { $this->write($line, 'n;red'); } else { $this->write($line); } } $this->write("\n\n"); } }
[ "protected", "function", "_renderCoverage", "(", "$", "metrics", ")", "{", "$", "stats", "=", "$", "metrics", "->", "data", "(", ")", ";", "foreach", "(", "$", "stats", "[", "'files'", "]", "as", "$", "file", ")", "{", "$", "this", "->", "write", "...
Outputs the coverage report of a metrics instance. @param Metrics $metrics A metrics instance.
[ "Outputs", "the", "coverage", "report", "of", "a", "metrics", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage.php#L324-L357
train
kahlan/kahlan
src/Reporter/Coverage.php
Coverage.stop
public function stop($summary) { $this->write("Coverage Summary\n----------------\n"); $verbosity = $this->_verbosity; $metrics = is_numeric($this->_verbosity) ? $this->metrics() : $this->metrics()->get($verbosity); if (!$metrics) { $this->write("\nUnexisting namespace/reference: `{$this->_verbosity}`, coverage can't be generated.\n\n", "n;yellow"); return; } $this->_renderMetrics($metrics, $verbosity); $this->write("\n"); if (is_string($verbosity)) { $this->_renderCoverage($metrics); $this->write("\n"); } // Output the original stored metrics object (the total coverage) $name = $metrics->name(); $stats = $metrics->data(); $percent = number_format($stats['percent'], 2); $this->write(str_repeat(' ', substr_count($name, '\\'))); $this->write('Total: '); $this->write("{$percent}% ", $this->_style($percent)); $this->write("({$stats['cloc']}/{$stats['lloc']})"); $this->write("\n"); // Output the time to collect coverage $time = number_format($this->_time, 3); $this->write("\nCoverage collected in {$time} seconds\n\n\n"); }
php
public function stop($summary) { $this->write("Coverage Summary\n----------------\n"); $verbosity = $this->_verbosity; $metrics = is_numeric($this->_verbosity) ? $this->metrics() : $this->metrics()->get($verbosity); if (!$metrics) { $this->write("\nUnexisting namespace/reference: `{$this->_verbosity}`, coverage can't be generated.\n\n", "n;yellow"); return; } $this->_renderMetrics($metrics, $verbosity); $this->write("\n"); if (is_string($verbosity)) { $this->_renderCoverage($metrics); $this->write("\n"); } // Output the original stored metrics object (the total coverage) $name = $metrics->name(); $stats = $metrics->data(); $percent = number_format($stats['percent'], 2); $this->write(str_repeat(' ', substr_count($name, '\\'))); $this->write('Total: '); $this->write("{$percent}% ", $this->_style($percent)); $this->write("({$stats['cloc']}/{$stats['lloc']})"); $this->write("\n"); // Output the time to collect coverage $time = number_format($this->_time, 3); $this->write("\nCoverage collected in {$time} seconds\n\n\n"); }
[ "public", "function", "stop", "(", "$", "summary", ")", "{", "$", "this", "->", "write", "(", "\"Coverage Summary\\n----------------\\n\"", ")", ";", "$", "verbosity", "=", "$", "this", "->", "_verbosity", ";", "$", "metrics", "=", "is_numeric", "(", "$", ...
Callback called at the end of the process. @param object $summary The execution summary instance.
[ "Callback", "called", "at", "the", "end", "of", "the", "process", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage.php#L385-L419
train
kahlan/kahlan
src/Matcher/ToHaveLength.php
ToHaveLength.actual
public static function actual($actual) { if (is_string($actual)) { return strlen($actual); } elseif (is_array($actual) || $actual instanceof Countable) { return count($actual); } }
php
public static function actual($actual) { if (is_string($actual)) { return strlen($actual); } elseif (is_array($actual) || $actual instanceof Countable) { return count($actual); } }
[ "public", "static", "function", "actual", "(", "$", "actual", ")", "{", "if", "(", "is_string", "(", "$", "actual", ")", ")", "{", "return", "strlen", "(", "$", "actual", ")", ";", "}", "elseif", "(", "is_array", "(", "$", "actual", ")", "||", "$",...
Normalize the actual value in the expected format. @param mixed $actual The actual value to be normalized. @return mixed The normalized value.
[ "Normalize", "the", "actual", "value", "in", "the", "expected", "format", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToHaveLength.php#L36-L43
train
kahlan/kahlan
src/Plugin/Call/Message.php
Message.match
public function match($call, $withArgs = true) { if (preg_match('/^::.*/', $call['name'])) { $call['static'] = true; $call['name'] = substr($call['name'], 2); } if (isset($call['static'])) { if ($call['static'] !== $this->_static) { return false; } } if ($call['name'] !== $this->_name) { return false; } if ($withArgs) { return $this->matchArgs($call['args']); } return true; }
php
public function match($call, $withArgs = true) { if (preg_match('/^::.*/', $call['name'])) { $call['static'] = true; $call['name'] = substr($call['name'], 2); } if (isset($call['static'])) { if ($call['static'] !== $this->_static) { return false; } } if ($call['name'] !== $this->_name) { return false; } if ($withArgs) { return $this->matchArgs($call['args']); } return true; }
[ "public", "function", "match", "(", "$", "call", ",", "$", "withArgs", "=", "true", ")", "{", "if", "(", "preg_match", "(", "'/^::.*/'", ",", "$", "call", "[", "'name'", "]", ")", ")", "{", "$", "call", "[", "'static'", "]", "=", "true", ";", "$"...
Check if this message is compatible with passed call array. @param array $call A call array. @param boolean $withArgs Boolean indicating if matching should take arguments into account. @return boolean
[ "Check", "if", "this", "message", "is", "compatible", "with", "passed", "call", "array", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Call/Message.php#L115-L137
train
kahlan/kahlan
src/Plugin/Call/Message.php
Message.matchArgs
public function matchArgs($args) { if ($this->_args === null || $args === null) { return true; } $arg = $this->_classes['arg']; foreach ($this->_args as $expected) { $actual = array_shift($args); if ($expected instanceof $arg) { if (!$expected->match($actual)) { return false; } } elseif ($actual !== $expected) { return false; } } return true; }
php
public function matchArgs($args) { if ($this->_args === null || $args === null) { return true; } $arg = $this->_classes['arg']; foreach ($this->_args as $expected) { $actual = array_shift($args); if ($expected instanceof $arg) { if (!$expected->match($actual)) { return false; } } elseif ($actual !== $expected) { return false; } } return true; }
[ "public", "function", "matchArgs", "(", "$", "args", ")", "{", "if", "(", "$", "this", "->", "_args", "===", "null", "||", "$", "args", "===", "null", ")", "{", "return", "true", ";", "}", "$", "arg", "=", "$", "this", "->", "_classes", "[", "'ar...
Check if this stub is compatible with passed args. @param array $args The passed arguments. @return boolean
[ "Check", "if", "this", "stub", "is", "compatible", "with", "passed", "args", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Call/Message.php#L145-L162
train
kahlan/kahlan
src/Matcher/ToThrow.php
ToThrow.expected
public static function expected($expected, $code = 0) { if ($expected === null || is_string($expected)) { return new AnyException($expected, $code); } return $expected; }
php
public static function expected($expected, $code = 0) { if ($expected === null || is_string($expected)) { return new AnyException($expected, $code); } return $expected; }
[ "public", "static", "function", "expected", "(", "$", "expected", ",", "$", "code", "=", "0", ")", "{", "if", "(", "$", "expected", "===", "null", "||", "is_string", "(", "$", "expected", ")", ")", "{", "return", "new", "AnyException", "(", "$", "exp...
Normalise the expected value as an Exception. @param mixed $expected The expected value to be normalized. @param integer $code The expected `Exception` code if `$expected` is a string. @return mixed The normalised value.
[ "Normalise", "the", "expected", "value", "as", "an", "Exception", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToThrow.php#L61-L67
train
kahlan/kahlan
src/Matcher/ToThrow.php
ToThrow._matchException
public static function _matchException($actual, $exception) { if (!$actual) { return false; } if ($exception instanceof AnyException) { $code = $exception->getCode() ? $actual->getCode() : $exception->getCode(); $class = get_class($actual); } else { $code = $actual->getCode(); $class = get_class($exception); } if (get_class($actual) !== $class) { return false; } $sameCode = $code === $exception->getCode(); $sameMessage = static::_sameMessage($actual->getMessage(), $exception->getMessage()); return $sameCode && $sameMessage; }
php
public static function _matchException($actual, $exception) { if (!$actual) { return false; } if ($exception instanceof AnyException) { $code = $exception->getCode() ? $actual->getCode() : $exception->getCode(); $class = get_class($actual); } else { $code = $actual->getCode(); $class = get_class($exception); } if (get_class($actual) !== $class) { return false; } $sameCode = $code === $exception->getCode(); $sameMessage = static::_sameMessage($actual->getMessage(), $exception->getMessage()); return $sameCode && $sameMessage; }
[ "public", "static", "function", "_matchException", "(", "$", "actual", ",", "$", "exception", ")", "{", "if", "(", "!", "$", "actual", ")", "{", "return", "false", ";", "}", "if", "(", "$", "exception", "instanceof", "AnyException", ")", "{", "$", "cod...
Compares if two exception are similar. @param object $actual The actual instance. @param \Exception $exception The exception instance. @return boolean
[ "Compares", "if", "two", "exception", "are", "similar", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToThrow.php#L76-L96
train
kahlan/kahlan
src/Matcher/ToThrow.php
ToThrow._sameMessage
public static function _sameMessage($actual, $expected) { if (preg_match('~^(?P<char>\~|/|@|#).*?(?P=char)$~', (string) $expected)) { $same = preg_match($expected, $actual); } else { $same = $actual === $expected; } return $same || !$expected; }
php
public static function _sameMessage($actual, $expected) { if (preg_match('~^(?P<char>\~|/|@|#).*?(?P=char)$~', (string) $expected)) { $same = preg_match($expected, $actual); } else { $same = $actual === $expected; } return $same || !$expected; }
[ "public", "static", "function", "_sameMessage", "(", "$", "actual", ",", "$", "expected", ")", "{", "if", "(", "preg_match", "(", "'~^(?P<char>\\~|/|@|#).*?(?P=char)$~'", ",", "(", "string", ")", "$", "expected", ")", ")", "{", "$", "same", "=", "preg_match"...
Compare if exception messages are similar. @param string $actual The actual message. @param string $expected The expected message. @return boolean
[ "Compare", "if", "exception", "messages", "are", "similar", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToThrow.php#L105-L113
train
kahlan/kahlan
src/Jit/Node/FunctionDef.php
FunctionDef.argsToParams
public function argsToParams() { $args = []; foreach ($this->args as $key => $value) { $value = is_int($key) ? $value : $key; preg_match("/(\\\$[\\\a-z_\\x7f-\\xff][a-z0-9_\\x7f-\\xff]*)/i", $value, $match); $args[] = $match[1]; } return join(', ', $args); }
php
public function argsToParams() { $args = []; foreach ($this->args as $key => $value) { $value = is_int($key) ? $value : $key; preg_match("/(\\\$[\\\a-z_\\x7f-\\xff][a-z0-9_\\x7f-\\xff]*)/i", $value, $match); $args[] = $match[1]; } return join(', ', $args); }
[ "public", "function", "argsToParams", "(", ")", "{", "$", "args", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "args", "as", "$", "key", "=>", "$", "value", ")", "{", "$", "value", "=", "is_int", "(", "$", "key", ")", "?", "$", "value...
Returns function's arguments into a list of callable parameters @return string
[ "Returns", "function", "s", "arguments", "into", "a", "list", "of", "callable", "parameters" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Node/FunctionDef.php#L67-L76
train
kahlan/kahlan
src/Box/Box.php
Box.factory
public function factory($name, $definition) { if (!is_string($definition) && !$definition instanceof Closure) { throw new BoxException("Error `{$name}` is not a closure definition dependency can't use it as a factory definition."); } $this->_set($name, $definition, 'factory'); }
php
public function factory($name, $definition) { if (!is_string($definition) && !$definition instanceof Closure) { throw new BoxException("Error `{$name}` is not a closure definition dependency can't use it as a factory definition."); } $this->_set($name, $definition, 'factory'); }
[ "public", "function", "factory", "(", "$", "name", ",", "$", "definition", ")", "{", "if", "(", "!", "is_string", "(", "$", "definition", ")", "&&", "!", "$", "definition", "instanceof", "Closure", ")", "{", "throw", "new", "BoxException", "(", "\"Error ...
Defining a factory. @param string $id The name of the definition. @param string|Closure $definition A fully namespaced classname or a closure. @throws BoxException if the definition is not a closure or a string.
[ "Defining", "a", "factory", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Box/Box.php#L45-L51
train
kahlan/kahlan
src/Box/Box.php
Box._set
protected function _set($name, $definition, $type) { if ($definition instanceof Closure) { $definition = $definition->bindTo($this, get_class($this)); } $this->_definitions[$name] = compact('definition', 'type'); }
php
protected function _set($name, $definition, $type) { if ($definition instanceof Closure) { $definition = $definition->bindTo($this, get_class($this)); } $this->_definitions[$name] = compact('definition', 'type'); }
[ "protected", "function", "_set", "(", "$", "name", ",", "$", "definition", ",", "$", "type", ")", "{", "if", "(", "$", "definition", "instanceof", "Closure", ")", "{", "$", "definition", "=", "$", "definition", "->", "bindTo", "(", "$", "this", ",", ...
Stores a dependency definition. @param string $id The name of the definition. @param mixed $definition The definition. @param mixed $type The type of the definition.
[ "Stores", "a", "dependency", "definition", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Box/Box.php#L71-L77
train
kahlan/kahlan
src/Box/Box.php
Box.get
public function get($name) { if (!isset($this->_definitions[$name])) { throw new BoxException("Unexisting `{$name}` definition dependency."); } extract($this->_definitions[$name]); if ($type === 'singleton') { return $definition; } $params = func_get_args(); array_shift($params); if ($type === 'service') { return $definition = $this->_service($name, $definition, $params); } return $definition = $this->_factory($definition, $params); }
php
public function get($name) { if (!isset($this->_definitions[$name])) { throw new BoxException("Unexisting `{$name}` definition dependency."); } extract($this->_definitions[$name]); if ($type === 'singleton') { return $definition; } $params = func_get_args(); array_shift($params); if ($type === 'service') { return $definition = $this->_service($name, $definition, $params); } return $definition = $this->_factory($definition, $params); }
[ "public", "function", "get", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_definitions", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "BoxException", "(", "\"Unexisting `{$name}` definition dependency.\"", ")", ";"...
Gets a shared variable or an new instance. @param string $name The name of the definition. @param mixed ... Parameter. @return mixed The shared variable or an new instance. @throws BoxException if the definition doesn't exists.
[ "Gets", "a", "shared", "variable", "or", "an", "new", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Box/Box.php#L98-L117
train
kahlan/kahlan
src/Box/Box.php
Box.wrap
public function wrap($name) { if (!isset($this->_definitions[$name])) { throw new BoxException("Unexisting `{$name}` definition dependency."); } if (!$this->_definitions[$name]['definition'] instanceof Closure) { throw new BoxException("Error `{$name}` is not a closure definition dependency can't be wrapped."); } $params = func_get_args(); array_shift($params); $wrapper = $this->_classes['wrapper']; return new $wrapper([ 'box' => $this, 'name' => $name, 'params' => $params ]); }
php
public function wrap($name) { if (!isset($this->_definitions[$name])) { throw new BoxException("Unexisting `{$name}` definition dependency."); } if (!$this->_definitions[$name]['definition'] instanceof Closure) { throw new BoxException("Error `{$name}` is not a closure definition dependency can't be wrapped."); } $params = func_get_args(); array_shift($params); $wrapper = $this->_classes['wrapper']; return new $wrapper([ 'box' => $this, 'name' => $name, 'params' => $params ]); }
[ "public", "function", "wrap", "(", "$", "name", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_definitions", "[", "$", "name", "]", ")", ")", "{", "throw", "new", "BoxException", "(", "\"Unexisting `{$name}` definition dependency.\"", ")", ";...
Returns a dependency container. @param string $name The name of the definition. @param mixed ... A list of parameters. @return mixed The shared variable or an new instance. @throws BoxException if the definition doesn't exists.
[ "Returns", "a", "dependency", "container", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Box/Box.php#L127-L145
train
kahlan/kahlan
src/Box/Box.php
Box._service
protected function _service($name, $definition, $params) { if ($definition instanceof Closure) { $type = 'singleton'; $definition = call_user_func_array($definition, $params); $this->_definitions[$name] = compact('definition', 'type'); } return $definition; }
php
protected function _service($name, $definition, $params) { if ($definition instanceof Closure) { $type = 'singleton'; $definition = call_user_func_array($definition, $params); $this->_definitions[$name] = compact('definition', 'type'); } return $definition; }
[ "protected", "function", "_service", "(", "$", "name", ",", "$", "definition", ",", "$", "params", ")", "{", "if", "(", "$", "definition", "instanceof", "Closure", ")", "{", "$", "type", "=", "'singleton'", ";", "$", "definition", "=", "call_user_func_arra...
Process a shared definition. @param string $name The name of the definition. @param mixed $definition A definition. @param array $params Parameters to pass to the definition. @return mixed
[ "Process", "a", "shared", "definition", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Box/Box.php#L155-L163
train
kahlan/kahlan
src/Box/Box.php
Box._factory
protected function _factory($definition, $params) { if (is_string($definition)) { if ($params) { $refl = new ReflectionClass($definition); return $refl->newInstanceArgs($params); } else { return new $definition(); } } return call_user_func_array($definition, $params); }
php
protected function _factory($definition, $params) { if (is_string($definition)) { if ($params) { $refl = new ReflectionClass($definition); return $refl->newInstanceArgs($params); } else { return new $definition(); } } return call_user_func_array($definition, $params); }
[ "protected", "function", "_factory", "(", "$", "definition", ",", "$", "params", ")", "{", "if", "(", "is_string", "(", "$", "definition", ")", ")", "{", "if", "(", "$", "params", ")", "{", "$", "refl", "=", "new", "ReflectionClass", "(", "$", "defin...
Process a setted definition. @param mixed $definition A definition. @param array $params Parameters to pass to the definition. @return mixed
[ "Process", "a", "setted", "definition", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Box/Box.php#L172-L183
train
kahlan/kahlan
src/Box/Wrapper.php
Wrapper.get
public function get() { if ($this->__resolved) { return $this->__dependency; } $this->__resolved = true; $params = func_num_args() === 0 ? $this->__params : func_get_args(); array_unshift($params, $this->__name); return $this->__dependency = call_user_func_array([$this->__box, 'get'], $params); }
php
public function get() { if ($this->__resolved) { return $this->__dependency; } $this->__resolved = true; $params = func_num_args() === 0 ? $this->__params : func_get_args(); array_unshift($params, $this->__name); return $this->__dependency = call_user_func_array([$this->__box, 'get'], $params); }
[ "public", "function", "get", "(", ")", "{", "if", "(", "$", "this", "->", "__resolved", ")", "{", "return", "$", "this", "->", "__dependency", ";", "}", "$", "this", "->", "__resolved", "=", "true", ";", "$", "params", "=", "func_num_args", "(", ")",...
Resolve the dependency. @return mixed The shared variable or an new instance. @param mixed ... A list of parameters. @throws BoxException
[ "Resolve", "the", "dependency", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Box/Wrapper.php#L75-L84
train
kahlan/kahlan
src/Jit/Patcher/Monkey.php
Monkey._flushVariables
protected function _flushVariables($node) { if (!$this->_variables[$this->_depth]) { return; } $body = ''; foreach ($this->_variables[$this->_depth] as $variable) { $body .= $variable['name'] . $variable['patch']; } if (!$node->inPhp) { $body = '<?php ' . $body . ' ?>'; } $patch = new NodeDef($body, 'code'); $patch->parent = $node; $patch->function = $node->function; $patch->namespace = $node->namespace; array_unshift($node->tree, $patch); $this->_variables[$this->_depth] = []; }
php
protected function _flushVariables($node) { if (!$this->_variables[$this->_depth]) { return; } $body = ''; foreach ($this->_variables[$this->_depth] as $variable) { $body .= $variable['name'] . $variable['patch']; } if (!$node->inPhp) { $body = '<?php ' . $body . ' ?>'; } $patch = new NodeDef($body, 'code'); $patch->parent = $node; $patch->function = $node->function; $patch->namespace = $node->namespace; array_unshift($node->tree, $patch); $this->_variables[$this->_depth] = []; }
[ "protected", "function", "_flushVariables", "(", "$", "node", ")", "{", "if", "(", "!", "$", "this", "->", "_variables", "[", "$", "this", "->", "_depth", "]", ")", "{", "return", ";", "}", "$", "body", "=", "''", ";", "foreach", "(", "$", "this", ...
Flush stored variables in the passed node. @param array $node The node to store variables in.
[ "Flush", "stored", "variables", "in", "the", "passed", "node", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Patcher/Monkey.php#L195-L216
train
kahlan/kahlan
src/Jit/Patcher/Monkey.php
Monkey._addClosingParenthesis
protected function _addClosingParenthesis($pos, $index, $parent) { $count = 0; $nodes = $parent->tree; $total = count($nodes); for ($i = $index; $i < $total; $i++) { $node = $nodes[$i]; if (!$node->processable || $node->type !== 'code') { if (!$node->close) { continue; } $code = &$node->close; } else { $code = &$node->body; } $len = strlen($code); while ($pos < $len) { if ($count === 0 && $code[$pos] === ';') { $code = substr_replace($code, ');', $pos, 1); return true; } elseif ($code[$pos] === '(') { $count++; } elseif ($code[$pos] === ')') { $count--; if ($count === 0) { $code = substr_replace($code, $code[$pos] . ')', $pos, 1); return true; } } $pos++; } $pos = 0; } return false; }
php
protected function _addClosingParenthesis($pos, $index, $parent) { $count = 0; $nodes = $parent->tree; $total = count($nodes); for ($i = $index; $i < $total; $i++) { $node = $nodes[$i]; if (!$node->processable || $node->type !== 'code') { if (!$node->close) { continue; } $code = &$node->close; } else { $code = &$node->body; } $len = strlen($code); while ($pos < $len) { if ($count === 0 && $code[$pos] === ';') { $code = substr_replace($code, ');', $pos, 1); return true; } elseif ($code[$pos] === '(') { $count++; } elseif ($code[$pos] === ')') { $count--; if ($count === 0) { $code = substr_replace($code, $code[$pos] . ')', $pos, 1); return true; } } $pos++; } $pos = 0; } return false; }
[ "protected", "function", "_addClosingParenthesis", "(", "$", "pos", ",", "$", "index", ",", "$", "parent", ")", "{", "$", "count", "=", "0", ";", "$", "nodes", "=", "$", "parent", "->", "tree", ";", "$", "total", "=", "count", "(", "$", "nodes", ")...
Add a closing parenthesis @param object $node The node to monkey patch. @param array $parent The parent array. @param integer $index The index of node in parent children. @return boolean Returns `true` if succeed, `false` otherwise.
[ "Add", "a", "closing", "parenthesis" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Patcher/Monkey.php#L293-L331
train
kahlan/kahlan
src/Jit/Patcher/Monkey.php
Monkey.blacklisted
public static function blacklisted($name = null) { if (!func_num_args()) { return array_keys(static::$_blacklist); } return isset(static::$_blacklist[strtolower($name)]); }
php
public static function blacklisted($name = null) { if (!func_num_args()) { return array_keys(static::$_blacklist); } return isset(static::$_blacklist[strtolower($name)]); }
[ "public", "static", "function", "blacklisted", "(", "$", "name", "=", "null", ")", "{", "if", "(", "!", "func_num_args", "(", ")", ")", "{", "return", "array_keys", "(", "static", "::", "$", "_blacklist", ")", ";", "}", "return", "isset", "(", "static"...
Check if a function is part of the blacklisted ones. @param string $name A function name. @return boolean
[ "Check", "if", "a", "function", "is", "part", "of", "the", "blacklisted", "ones", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Patcher/Monkey.php#L339-L345
train
kahlan/kahlan
src/Matcher/ToBeA.php
ToBeA.expected
public static function expected($expected) { if ($expected === 'bool') { $expected = 'boolean'; } if ($expected === 'int') { $expected = 'integer'; } if ($expected === 'float') { $expected = 'double'; } return strtolower($expected); }
php
public static function expected($expected) { if ($expected === 'bool') { $expected = 'boolean'; } if ($expected === 'int') { $expected = 'integer'; } if ($expected === 'float') { $expected = 'double'; } return strtolower($expected); }
[ "public", "static", "function", "expected", "(", "$", "expected", ")", "{", "if", "(", "$", "expected", "===", "'bool'", ")", "{", "$", "expected", "=", "'boolean'", ";", "}", "if", "(", "$", "expected", "===", "'int'", ")", "{", "$", "expected", "="...
Normalises the expected value. @param mixed $expected The expected value to be normalized. @return mixed The normalized value.
[ "Normalises", "the", "expected", "value", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher/ToBeA.php#L46-L58
train
kahlan/kahlan
src/Plugin/Double.php
Double.instance
public static function instance($options = []) { $class = static::classname($options); if (isset($options['args'])) { $refl = new ReflectionClass($class); $instance = $refl->newInstanceArgs($options['args']); } else { $instance = new $class(); } if (isset($options['stubMethods']) && is_array($options['stubMethods'])) { foreach ($options['stubMethods'] as $name => $return) { allow($instance)->toReceive($name)->andReturn($return); } } if (isset($options['fakeMethods']) && is_array($options['fakeMethods'])) { foreach ($options['fakeMethods'] as $name => $callback) { allow($instance)->toReceive($name)->andRun($callback); } } return $instance; }
php
public static function instance($options = []) { $class = static::classname($options); if (isset($options['args'])) { $refl = new ReflectionClass($class); $instance = $refl->newInstanceArgs($options['args']); } else { $instance = new $class(); } if (isset($options['stubMethods']) && is_array($options['stubMethods'])) { foreach ($options['stubMethods'] as $name => $return) { allow($instance)->toReceive($name)->andReturn($return); } } if (isset($options['fakeMethods']) && is_array($options['fakeMethods'])) { foreach ($options['fakeMethods'] as $name => $callback) { allow($instance)->toReceive($name)->andRun($callback); } } return $instance; }
[ "public", "static", "function", "instance", "(", "$", "options", "=", "[", "]", ")", "{", "$", "class", "=", "static", "::", "classname", "(", "$", "options", ")", ";", "if", "(", "isset", "(", "$", "options", "[", "'args'", "]", ")", ")", "{", "...
Creates a polyvalent instance. @param array $options Array of options. Options are: - `'class'` string : the fully-namespaced class name. - `'extends'` string : the fully-namespaced parent class name. - `'args'` array : arguments to pass to the constructor. - `'methods'` string[]: override given methods with empty functions. - `'stubMethods'` array : override given methods to return given values, e.g. ['foo' => 'bar']. - `'fakeMethods'` array : override given methods to run given callback, e.g. ['foo' => function () { return 'bar'; }]. @return object The created instance.
[ "Creates", "a", "polyvalent", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L56-L77
train
kahlan/kahlan
src/Plugin/Double.php
Double.classname
public static function classname($options = []) { $defaults = ['class' => 'Kahlan\Spec\Plugin\Double\Double' . static::$_index++]; $options += $defaults; if (!static::$_pointcut) { $pointcut = static::$_classes['pointcut']; static::$_pointcut = new $pointcut(); } if (!class_exists($options['class'], false)) { $parser = static::$_classes['parser']; $code = static::generate($options); $nodes = $parser::parse($code); $code = $parser::unparse(static::$_pointcut->process($nodes)); eval('?>' . $code); } return $options['class']; }
php
public static function classname($options = []) { $defaults = ['class' => 'Kahlan\Spec\Plugin\Double\Double' . static::$_index++]; $options += $defaults; if (!static::$_pointcut) { $pointcut = static::$_classes['pointcut']; static::$_pointcut = new $pointcut(); } if (!class_exists($options['class'], false)) { $parser = static::$_classes['parser']; $code = static::generate($options); $nodes = $parser::parse($code); $code = $parser::unparse(static::$_pointcut->process($nodes)); eval('?>' . $code); } return $options['class']; }
[ "public", "static", "function", "classname", "(", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'class'", "=>", "'Kahlan\\Spec\\Plugin\\Double\\Double'", ".", "static", "::", "$", "_index", "++", "]", ";", "$", "options", "+=", "$", ...
Creates a polyvalent static class. @param array $options Array of options. Options are: - `'class'` : the fully-namespaced class name. - `'extends'` : the fully-namespaced parent class name. @return string The created fully-namespaced class name.
[ "Creates", "a", "polyvalent", "static", "class", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L87-L105
train
kahlan/kahlan
src/Plugin/Double.php
Double.generate
public static function generate($options = []) { $defaults = [ 'class' => 'Kahlan\Spec\Plugin\Double\Double' . static::$_index++, 'extends' => '', 'implements' => [], 'uses' => [], 'methods' => [], 'layer' => null, 'openTag' => true, 'closeTag' => true ]; $options += $defaults; if ($options['extends'] || $options['implements']) { $options += ['magicMethods' => false]; } else { $options += ['magicMethods' => true]; } $class = $options['class']; $namespace = ''; if (($pos = strrpos($class, '\\')) !== false) { $namespace = substr($class, 0, $pos); $class = substr($class, $pos + 1); } if ($namespace) { $namespace = "namespace {$namespace};\n"; } $uses = static::_generateUses($options['uses']); $extends = static::_generateExtends($options['extends']); $implements = static::_generateImplements($options['implements']); $methods = static::_generateMethodStubs($options['methods'], $options['magicMethods']); if ($options['extends']) { $methods += static::_generateClassMethods($options['extends'], $options['layer']); } $methods += static::_generateInterfaceMethods($options['implements']); $methods = $methods ? ' ' . join("\n ", $methods) : ''; $openTag = $options['openTag'] ? "<?php\n" : ''; $closeTag = $options['closeTag'] ? "?>" : ''; return $openTag . $namespace . <<<EOT class {$class}{$extends}{$implements} { {$uses}{$methods} } $closeTag EOT; }
php
public static function generate($options = []) { $defaults = [ 'class' => 'Kahlan\Spec\Plugin\Double\Double' . static::$_index++, 'extends' => '', 'implements' => [], 'uses' => [], 'methods' => [], 'layer' => null, 'openTag' => true, 'closeTag' => true ]; $options += $defaults; if ($options['extends'] || $options['implements']) { $options += ['magicMethods' => false]; } else { $options += ['magicMethods' => true]; } $class = $options['class']; $namespace = ''; if (($pos = strrpos($class, '\\')) !== false) { $namespace = substr($class, 0, $pos); $class = substr($class, $pos + 1); } if ($namespace) { $namespace = "namespace {$namespace};\n"; } $uses = static::_generateUses($options['uses']); $extends = static::_generateExtends($options['extends']); $implements = static::_generateImplements($options['implements']); $methods = static::_generateMethodStubs($options['methods'], $options['magicMethods']); if ($options['extends']) { $methods += static::_generateClassMethods($options['extends'], $options['layer']); } $methods += static::_generateInterfaceMethods($options['implements']); $methods = $methods ? ' ' . join("\n ", $methods) : ''; $openTag = $options['openTag'] ? "<?php\n" : ''; $closeTag = $options['closeTag'] ? "?>" : ''; return $openTag . $namespace . <<<EOT class {$class}{$extends}{$implements} { {$uses}{$methods} } $closeTag EOT; }
[ "public", "static", "function", "generate", "(", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'class'", "=>", "'Kahlan\\Spec\\Plugin\\Double\\Double'", ".", "static", "::", "$", "_index", "++", ",", "'extends'", "=>", "''", ",", "'i...
Creates a class definition. @param array $options Array of options. Options are: - `'class'` _string_ : the fully-namespaced class name. - `'extends'` _string_ : the fully-namespaced parent class name. - `'implements'` _array_ : the implemented interfaces. - `'uses'` _array_ : the used traits. - `'methods'` _array_ : the methods to stubs. - `'layer'` _boolean_: indicate if public methods should be layered. @return string The generated class string content.
[ "Creates", "a", "class", "definition", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L119-L174
train
kahlan/kahlan
src/Plugin/Double.php
Double._generateUses
protected static function _generateUses($uses) { if (!$uses) { return ''; } $traits = []; foreach ((array) $uses as $use) { if (!trait_exists($use)) { throw new MissingImplementationException("Unexisting trait `{$use}`"); } $traits[] = '\\' . ltrim($use, '\\'); } return ' use ' . join(', ', $traits) . ';'; }
php
protected static function _generateUses($uses) { if (!$uses) { return ''; } $traits = []; foreach ((array) $uses as $use) { if (!trait_exists($use)) { throw new MissingImplementationException("Unexisting trait `{$use}`"); } $traits[] = '\\' . ltrim($use, '\\'); } return ' use ' . join(', ', $traits) . ';'; }
[ "protected", "static", "function", "_generateUses", "(", "$", "uses", ")", "{", "if", "(", "!", "$", "uses", ")", "{", "return", "''", ";", "}", "$", "traits", "=", "[", "]", ";", "foreach", "(", "(", "array", ")", "$", "uses", "as", "$", "use", ...
Creates a `use` definition. @param array $uses An array of traits. @return string The generated `use` definition.
[ "Creates", "a", "use", "definition", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L207-L220
train
kahlan/kahlan
src/Plugin/Double.php
Double._generateMethodStubs
protected static function _generateMethodStubs($methods, $defaults = true) { $result = []; $methods = $methods !== null ? (array) $methods : []; if ($defaults) { $methods = array_merge($methods, array_keys(static::_getMagicMethods())); } $methods = array_unique($methods); $magicMethods = static::_getMagicMethods(); foreach ($methods as $name) { if (isset($magicMethods[$name])) { $result[$name] = $magicMethods[$name]; } else { $static = $return = ''; if ($name[0] === '&') { $return = '$r = null; return $r;'; } if (preg_match('/^&?::.*/', $name)) { $static = 'static '; $name = substr($name, 2); } $result[$name] = "public {$static}function {$name}() {{$return}}"; } } return $result; }
php
protected static function _generateMethodStubs($methods, $defaults = true) { $result = []; $methods = $methods !== null ? (array) $methods : []; if ($defaults) { $methods = array_merge($methods, array_keys(static::_getMagicMethods())); } $methods = array_unique($methods); $magicMethods = static::_getMagicMethods(); foreach ($methods as $name) { if (isset($magicMethods[$name])) { $result[$name] = $magicMethods[$name]; } else { $static = $return = ''; if ($name[0] === '&') { $return = '$r = null; return $r;'; } if (preg_match('/^&?::.*/', $name)) { $static = 'static '; $name = substr($name, 2); } $result[$name] = "public {$static}function {$name}() {{$return}}"; } } return $result; }
[ "protected", "static", "function", "_generateMethodStubs", "(", "$", "methods", ",", "$", "defaults", "=", "true", ")", "{", "$", "result", "=", "[", "]", ";", "$", "methods", "=", "$", "methods", "!==", "null", "?", "(", "array", ")", "$", "methods", ...
Creates method stubs. @param array $methods An array of method definitions. @param boolean $defaults If `true`, Magic Methods will be appended. @return array The generated method definitions.
[ "Creates", "method", "stubs", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L261-L290
train
kahlan/kahlan
src/Plugin/Double.php
Double._generateInterfaceMethods
protected static function _generateInterfaceMethods($interfaces, $mask = 255) { if (!$interfaces) { return []; } $result = []; foreach ((array) $interfaces as $interface) { if (!interface_exists($interface)) { throw new MissingImplementationException("Unexisting interface `{$interface}`"); } $reflection = Inspector::inspect($interface); $methods = $reflection->getMethods($mask); foreach ($methods as $method) { $result[$method->getName()] = static::_generateMethod($method); } } return $result; }
php
protected static function _generateInterfaceMethods($interfaces, $mask = 255) { if (!$interfaces) { return []; } $result = []; foreach ((array) $interfaces as $interface) { if (!interface_exists($interface)) { throw new MissingImplementationException("Unexisting interface `{$interface}`"); } $reflection = Inspector::inspect($interface); $methods = $reflection->getMethods($mask); foreach ($methods as $method) { $result[$method->getName()] = static::_generateMethod($method); } } return $result; }
[ "protected", "static", "function", "_generateInterfaceMethods", "(", "$", "interfaces", ",", "$", "mask", "=", "255", ")", "{", "if", "(", "!", "$", "interfaces", ")", "{", "return", "[", "]", ";", "}", "$", "result", "=", "[", "]", ";", "foreach", "...
Creates method definitions from an interface array. @param array $interfaces A array on interfaces. @param integer $mask The method mask to filter. @return array The generated methods.
[ "Creates", "method", "definitions", "from", "an", "interface", "array", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L352-L369
train
kahlan/kahlan
src/Plugin/Double.php
Double._generateMethod
protected static function _generateMethod($method, $callParent = false) { $result = join(' ', Reflection::getModifierNames($method->getModifiers())); $result = preg_replace('/abstract\s*/', '', $result); $name = $method->getName(); $parameters = static::_generateSignature($method); $type = static::_generateReturnType($method); $body = "{$result} function {$name}({$parameters}) {$type}{"; if ($callParent) { $parameters = static::_generateParameters($method); $return = 'return '; if ($method->isConstructor() || $method->isDestructor()) { $return = ''; } $body .= "{$return}parent::{$name}({$parameters});"; } return $body . "}"; }
php
protected static function _generateMethod($method, $callParent = false) { $result = join(' ', Reflection::getModifierNames($method->getModifiers())); $result = preg_replace('/abstract\s*/', '', $result); $name = $method->getName(); $parameters = static::_generateSignature($method); $type = static::_generateReturnType($method); $body = "{$result} function {$name}({$parameters}) {$type}{"; if ($callParent) { $parameters = static::_generateParameters($method); $return = 'return '; if ($method->isConstructor() || $method->isDestructor()) { $return = ''; } $body .= "{$return}parent::{$name}({$parameters});"; } return $body . "}"; }
[ "protected", "static", "function", "_generateMethod", "(", "$", "method", ",", "$", "callParent", "=", "false", ")", "{", "$", "result", "=", "join", "(", "' '", ",", "Reflection", "::", "getModifierNames", "(", "$", "method", "->", "getModifiers", "(", ")...
Creates a method definition from a `ReflectionMethod` instance. @param object $method A instance of `ReflectionMethod`. @return string The generated method.
[ "Creates", "a", "method", "definition", "from", "a", "ReflectionMethod", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L377-L394
train
kahlan/kahlan
src/Plugin/Double.php
Double._generateReturnType
protected static function _generateReturnType($method) { if (Suite::$PHP < 7) { return ''; } $type = $method->getReturnType(); $allowsNull = ''; if ($type) { if (method_exists($type, 'allowsNull') && $type->allowsNull()) { $allowsNull = '?'; } if (!$type->isBuiltin()) { $type = '\\' . $type; } if (defined('HHVM_VERSION')) { $type = preg_replace('~\\\?HH\\\(mixed|void)?~', '', $type); } } return $type ? ": {$allowsNull}{$type} " : ''; }
php
protected static function _generateReturnType($method) { if (Suite::$PHP < 7) { return ''; } $type = $method->getReturnType(); $allowsNull = ''; if ($type) { if (method_exists($type, 'allowsNull') && $type->allowsNull()) { $allowsNull = '?'; } if (!$type->isBuiltin()) { $type = '\\' . $type; } if (defined('HHVM_VERSION')) { $type = preg_replace('~\\\?HH\\\(mixed|void)?~', '', $type); } } return $type ? ": {$allowsNull}{$type} " : ''; }
[ "protected", "static", "function", "_generateReturnType", "(", "$", "method", ")", "{", "if", "(", "Suite", "::", "$", "PHP", "<", "7", ")", "{", "return", "''", ";", "}", "$", "type", "=", "$", "method", "->", "getReturnType", "(", ")", ";", "$", ...
Extract the return type of a method. @param object $method A instance of `ReflectionMethod`. @return string The return type.
[ "Extract", "the", "return", "type", "of", "a", "method", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L402-L421
train
kahlan/kahlan
src/Plugin/Double.php
Double._generateSignature
protected static function _generateSignature($method) { $params = []; $isVariadic = Suite::$PHP >= 7 ? $method->isVariadic() : false; foreach ($method->getParameters() as $num => $parameter) { $typehint = Inspector::typehint($parameter); $name = $parameter->getName(); $name = ($name && $name !== '...') ? $name : 'param' . $num; $reference = $parameter->isPassedByReference() ? '&' : ''; $default = ''; if ($parameter->isDefaultValueAvailable()) { $default = var_export($parameter->getDefaultValue(), true); $default = ' = ' . preg_replace('/\s+/', '', $default); } elseif ($parameter->isOptional()) { if ($isVariadic && $parameter->isVariadic()) { $reference = '...'; $default = ''; } else { $default = ' = NULL'; } } $allowsNull = ''; $typehint = $typehint ? $typehint . ' ' : $typehint; if (Suite::$PHP >= 7) { $type = $parameter->getType(); if ($type && method_exists($type, 'allowsNull') && $type->allowsNull()) { $allowsNull = '?'; } } $params[] = "{$allowsNull}{$typehint}{$reference}\${$name}{$default}"; } return join(', ', $params); }
php
protected static function _generateSignature($method) { $params = []; $isVariadic = Suite::$PHP >= 7 ? $method->isVariadic() : false; foreach ($method->getParameters() as $num => $parameter) { $typehint = Inspector::typehint($parameter); $name = $parameter->getName(); $name = ($name && $name !== '...') ? $name : 'param' . $num; $reference = $parameter->isPassedByReference() ? '&' : ''; $default = ''; if ($parameter->isDefaultValueAvailable()) { $default = var_export($parameter->getDefaultValue(), true); $default = ' = ' . preg_replace('/\s+/', '', $default); } elseif ($parameter->isOptional()) { if ($isVariadic && $parameter->isVariadic()) { $reference = '...'; $default = ''; } else { $default = ' = NULL'; } } $allowsNull = ''; $typehint = $typehint ? $typehint . ' ' : $typehint; if (Suite::$PHP >= 7) { $type = $parameter->getType(); if ($type && method_exists($type, 'allowsNull') && $type->allowsNull()) { $allowsNull = '?'; } } $params[] = "{$allowsNull}{$typehint}{$reference}\${$name}{$default}"; } return join(', ', $params); }
[ "protected", "static", "function", "_generateSignature", "(", "$", "method", ")", "{", "$", "params", "=", "[", "]", ";", "$", "isVariadic", "=", "Suite", "::", "$", "PHP", ">=", "7", "?", "$", "method", "->", "isVariadic", "(", ")", ":", "false", ";...
Creates a parameters signature of a `ReflectionMethod` instance. @param object $method A instance of `ReflectionMethod`. @return string The parameters definition list.
[ "Creates", "a", "parameters", "signature", "of", "a", "ReflectionMethod", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L429-L462
train
kahlan/kahlan
src/Plugin/Double.php
Double._generateParameters
protected static function _generateParameters($method) { $params = []; foreach ($method->getParameters() as $num => $parameter) { $name = $parameter->getName(); $name = ($name && $name !== '...') ? $name : 'param' . $num; $params[] = "\${$name}"; } return join(', ', $params); }
php
protected static function _generateParameters($method) { $params = []; foreach ($method->getParameters() as $num => $parameter) { $name = $parameter->getName(); $name = ($name && $name !== '...') ? $name : 'param' . $num; $params[] = "\${$name}"; } return join(', ', $params); }
[ "protected", "static", "function", "_generateParameters", "(", "$", "method", ")", "{", "$", "params", "=", "[", "]", ";", "foreach", "(", "$", "method", "->", "getParameters", "(", ")", "as", "$", "num", "=>", "$", "parameter", ")", "{", "$", "name", ...
Creates a parameters list from a `ReflectionMethod` instance. @param object $method A instance of `ReflectionMethod`. @return string The parameters definition list.
[ "Creates", "a", "parameters", "list", "from", "a", "ReflectionMethod", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Double.php#L470-L479
train
kahlan/kahlan
src/Filter/Filters.php
Filters.apply
public static function apply($context, $method, $filter) { static::$_cachedFilters = []; if (is_object($context)) { $instance = $context; $class = get_class($context); } else { $class = $context; $instance = null; } $filter = $filter->bindTo($instance, $class); $ref = static::_ref($context, $method); if (!isset(static::$_filters[$ref])) { static::$_filters[$ref] = [$filter]; } else { array_unshift(static::$_filters[$ref], $filter); } return $ref . '|' . (count(static::$_filters[$ref]) - 1); }
php
public static function apply($context, $method, $filter) { static::$_cachedFilters = []; if (is_object($context)) { $instance = $context; $class = get_class($context); } else { $class = $context; $instance = null; } $filter = $filter->bindTo($instance, $class); $ref = static::_ref($context, $method); if (!isset(static::$_filters[$ref])) { static::$_filters[$ref] = [$filter]; } else { array_unshift(static::$_filters[$ref], $filter); } return $ref . '|' . (count(static::$_filters[$ref]) - 1); }
[ "public", "static", "function", "apply", "(", "$", "context", ",", "$", "method", ",", "$", "filter", ")", "{", "static", "::", "$", "_cachedFilters", "=", "[", "]", ";", "if", "(", "is_object", "(", "$", "context", ")", ")", "{", "$", "instance", ...
Applies a filter. @param mixed $context An instance or a fully-namespaced class name. @param string $method A method name. @param string $filter The filter to apply. @return string The filter id. @throws InvalidArgumentException
[ "Applies", "a", "filter", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Filter/Filters.php#L56-L77
train
kahlan/kahlan
src/Filter/Filters.php
Filters._ref
protected static function _ref($context, $method) { if (is_string($context)) { return $context . "::{$method}"; } return get_class($context) . '#' . spl_object_hash($context) . "::{$method}"; }
php
protected static function _ref($context, $method) { if (is_string($context)) { return $context . "::{$method}"; } return get_class($context) . '#' . spl_object_hash($context) . "::{$method}"; }
[ "protected", "static", "function", "_ref", "(", "$", "context", ",", "$", "method", ")", "{", "if", "(", "is_string", "(", "$", "context", ")", ")", "{", "return", "$", "context", ".", "\"::{$method}\"", ";", "}", "return", "get_class", "(", "$", "cont...
Generates a reference id from a provided callable definition. @param mixed $context An instance or fully-namespaced class name. @param string $method A method name. @return string A reference id.
[ "Generates", "a", "reference", "id", "from", "a", "provided", "callable", "definition", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Filter/Filters.php#L86-L92
train
kahlan/kahlan
src/Filter/Filters.php
Filters.detach
public static function detach($context, $method = null) { if (func_num_args() === 2) { $value = static::_ref($context, $method); } else { $value = $context; } if (strpos($value, '|') !== false) { list($ref, $num) = explode('|', $value); if (!isset(static::$_filters[$ref][$num])) { throw new Exception("Unexisting `'{$value}'` filter id."); } $result = static::$_filters[$ref][$num]; unset(static::$_filters[$ref][$num]); } else { if (!isset(static::$_filters[$value])) { throw new Exception("Unexisting `'{$value}'` filter reference id."); } $result = static::$_filters[$value]; unset(static::$_filters[$value]); } return $result; }
php
public static function detach($context, $method = null) { if (func_num_args() === 2) { $value = static::_ref($context, $method); } else { $value = $context; } if (strpos($value, '|') !== false) { list($ref, $num) = explode('|', $value); if (!isset(static::$_filters[$ref][$num])) { throw new Exception("Unexisting `'{$value}'` filter id."); } $result = static::$_filters[$ref][$num]; unset(static::$_filters[$ref][$num]); } else { if (!isset(static::$_filters[$value])) { throw new Exception("Unexisting `'{$value}'` filter reference id."); } $result = static::$_filters[$value]; unset(static::$_filters[$value]); } return $result; }
[ "public", "static", "function", "detach", "(", "$", "context", ",", "$", "method", "=", "null", ")", "{", "if", "(", "func_num_args", "(", ")", "===", "2", ")", "{", "$", "value", "=", "static", "::", "_ref", "(", "$", "context", ",", "$", "method"...
Detaches a filter. @param object|string $context An instance, a fully-namespaced class name or a filter id to detach. @param string $method The name of the method to remove filter on or none if a filter id has been provided in `$context`. @return Closure|array Returns the removed closure if `$context` is a filter id. Otherwise it returns the array of closures attached to the provided class/method reference.
[ "Detaches", "a", "filter", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Filter/Filters.php#L103-L125
train
kahlan/kahlan
src/Filter/Filters.php
Filters.run
public static function run($context, $method, $params, $callback, $filters = []) { if (static::$_enabled) { $filters = array_merge($filters, static::filters($context, $method)); } $filters[] = $callback; $generator = static::_generator($filters); $next = function () use ($params, $generator, &$next) { $args = func_get_args() + $params; $closure = $generator->current(); $generator->next(); array_unshift($args, $next); return call_user_func_array($closure, $args); }; return call_user_func_array($next, $params); }
php
public static function run($context, $method, $params, $callback, $filters = []) { if (static::$_enabled) { $filters = array_merge($filters, static::filters($context, $method)); } $filters[] = $callback; $generator = static::_generator($filters); $next = function () use ($params, $generator, &$next) { $args = func_get_args() + $params; $closure = $generator->current(); $generator->next(); array_unshift($args, $next); return call_user_func_array($closure, $args); }; return call_user_func_array($next, $params); }
[ "public", "static", "function", "run", "(", "$", "context", ",", "$", "method", ",", "$", "params", ",", "$", "callback", ",", "$", "filters", "=", "[", "]", ")", "{", "if", "(", "static", "::", "$", "_enabled", ")", "{", "$", "filters", "=", "ar...
Cuts the normal execution of a method to run all applied filter for the method. @param mixed $context An instance or a fully-namespaced class name to run filters on. @param string $method The method name. @param array $params The parameters the pass to the original method. @param Closure $callback The original method closure. @param array $filters Additional filters to apply on this run. @return mixed
[ "Cuts", "the", "normal", "execution", "of", "a", "method", "to", "run", "all", "applied", "filter", "for", "the", "method", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Filter/Filters.php#L191-L207
train
kahlan/kahlan
src/Cli/Cli.php
Cli.color
public static function color($string, $options = null) { if ($options === null) { return $string; } if (is_string($options)) { $options = explode(';', $options); if (strlen($options[0]) === 1) { $options = array_pad($options, 3, 'default'); $options = array_combine(['style', 'color', 'background'], $options); } else { $options = ['color' => reset($options)]; } } $options += [ 'style' => 'default', 'color' => 'default', 'background' => 'default' ]; $format = "\e["; $format .= static::_vtstyle($options['style']) . ';'; $format .= static::_vtcolor($options['color']) . ';'; $format .= static::_vtbackground($options['background']) . 'm'; return $format . $string . "\e[0m"; }
php
public static function color($string, $options = null) { if ($options === null) { return $string; } if (is_string($options)) { $options = explode(';', $options); if (strlen($options[0]) === 1) { $options = array_pad($options, 3, 'default'); $options = array_combine(['style', 'color', 'background'], $options); } else { $options = ['color' => reset($options)]; } } $options += [ 'style' => 'default', 'color' => 'default', 'background' => 'default' ]; $format = "\e["; $format .= static::_vtstyle($options['style']) . ';'; $format .= static::_vtcolor($options['color']) . ';'; $format .= static::_vtbackground($options['background']) . 'm'; return $format . $string . "\e[0m"; }
[ "public", "static", "function", "color", "(", "$", "string", ",", "$", "options", "=", "null", ")", "{", "if", "(", "$", "options", "===", "null", ")", "{", "return", "$", "string", ";", "}", "if", "(", "is_string", "(", "$", "options", ")", ")", ...
Return a VT100 colored string. @param mixed $string The string to color. @param string|array $options The possible values for an array are: - `'style`: a style code. - `'color'`: a color code. - `'background'`: a background color code. The string must respect one of the following format: - `'style;color;background'`. - `'style;color'`. - `'color'`.
[ "Return", "a", "VT100", "colored", "string", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Cli/Cli.php#L144-L172
train
kahlan/kahlan
src/Util/Text.php
Text.toString
public static function toString($value, $options = []) { $defaults = [ 'quote' => '"', 'object' => [ 'method' => '__toString' ], 'array' => [ 'indent' => 1, 'char' => ' ', 'multiplier' => 4 ] ]; $options += $defaults; $options['array'] += $defaults['array']; $options['object'] += $defaults['object']; if ($value instanceof Closure) { return '`Closure`'; } if (is_array($value)) { return static::_arrayToString($value, $options); } if (is_object($value)) { return static::_objectToString($value, $options); } return static::dump($value, $options['quote']); }
php
public static function toString($value, $options = []) { $defaults = [ 'quote' => '"', 'object' => [ 'method' => '__toString' ], 'array' => [ 'indent' => 1, 'char' => ' ', 'multiplier' => 4 ] ]; $options += $defaults; $options['array'] += $defaults['array']; $options['object'] += $defaults['object']; if ($value instanceof Closure) { return '`Closure`'; } if (is_array($value)) { return static::_arrayToString($value, $options); } if (is_object($value)) { return static::_objectToString($value, $options); } return static::dump($value, $options['quote']); }
[ "public", "static", "function", "toString", "(", "$", "value", ",", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'quote'", "=>", "'\"'", ",", "'object'", "=>", "[", "'method'", "=>", "'__toString'", "]", ",", "'array'", "=>", ...
Generate a string representation of arbitrary data. @param mixed $value The data to dump in string. @param array $options Available options are: - `'quote'` : dump will quote string data if true (default `true`). - `'object'`: dump options for objects. - `'method'`: default method to call on string instance (default `__toString`). - `'array'` : dump options for arrays. - `'indent'`: level of indent (defaults to `1`). - `'char'`: indentation character. - `'multiplier'`: number of indentation character per indent (default `4`) @return string The dumped string.
[ "Generate", "a", "string", "representation", "of", "arbitrary", "data", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Util/Text.php#L125-L154
train