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/Util/Text.php
Text._arrayToString
protected static function _arrayToString($data, $options) { if (empty($data)) { return '[]'; } extract($options['array']); /** * @var string $char * @var int $indent * @var int $multiplier */ $comma = false; $tab = str_repeat($char, $indent * $multiplier); $string = "[\n"; foreach ($data as $key => $value) { if ($comma) { $string .= ",\n"; } $comma = true; $key = filter_var($key, FILTER_VALIDATE_INT) ? $key : static::dump($key, $options['quote']); $string .= $tab . $key . ' => '; if (is_array($value)) { $options['array']['indent'] = $indent + 1; $string .= static::_arrayToString($value, $options); } else { $string .= static::toString($value, $options); } } $tab = str_repeat($char, ($indent - 1) * $multiplier); return $string . "\n" . $tab . "]"; }
php
protected static function _arrayToString($data, $options) { if (empty($data)) { return '[]'; } extract($options['array']); /** * @var string $char * @var int $indent * @var int $multiplier */ $comma = false; $tab = str_repeat($char, $indent * $multiplier); $string = "[\n"; foreach ($data as $key => $value) { if ($comma) { $string .= ",\n"; } $comma = true; $key = filter_var($key, FILTER_VALIDATE_INT) ? $key : static::dump($key, $options['quote']); $string .= $tab . $key . ' => '; if (is_array($value)) { $options['array']['indent'] = $indent + 1; $string .= static::_arrayToString($value, $options); } else { $string .= static::toString($value, $options); } } $tab = str_repeat($char, ($indent - 1) * $multiplier); return $string . "\n" . $tab . "]"; }
[ "protected", "static", "function", "_arrayToString", "(", "$", "data", ",", "$", "options", ")", "{", "if", "(", "empty", "(", "$", "data", ")", ")", "{", "return", "'[]'", ";", "}", "extract", "(", "$", "options", "[", "'array'", "]", ")", ";", "/...
Generate a string representation of an array. @param array $data An array. @param array $options An array of options. @return string The dumped string.
[ "Generate", "a", "string", "representation", "of", "an", "array", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Util/Text.php#L164-L198
train
kahlan/kahlan
src/Util/Text.php
Text._objectToString
protected static function _objectToString($value, $options) { if ($value instanceof Exception) { $msg = '`' . get_class($value) .'` Code(' . $value->getCode() . ') with '; $message = $value->getMessage(); if ($message) { $msg .= 'message '. static::dump($value->getMessage()); } else { $msg .= 'no message'; } return $msg . ' in '. $value->getFile() . ':' . $value->getLine(); } $method = $options['object']['method']; if (is_callable($method)) { return $method($value); } if (!$method || !method_exists($value, $method)) { return '`' . get_class($value) . '`'; } return $value->{$method}(); }
php
protected static function _objectToString($value, $options) { if ($value instanceof Exception) { $msg = '`' . get_class($value) .'` Code(' . $value->getCode() . ') with '; $message = $value->getMessage(); if ($message) { $msg .= 'message '. static::dump($value->getMessage()); } else { $msg .= 'no message'; } return $msg . ' in '. $value->getFile() . ':' . $value->getLine(); } $method = $options['object']['method']; if (is_callable($method)) { return $method($value); } if (!$method || !method_exists($value, $method)) { return '`' . get_class($value) . '`'; } return $value->{$method}(); }
[ "protected", "static", "function", "_objectToString", "(", "$", "value", ",", "$", "options", ")", "{", "if", "(", "$", "value", "instanceof", "Exception", ")", "{", "$", "msg", "=", "'`'", ".", "get_class", "(", "$", "value", ")", ".", "'` Code('", "....
Generate a string representation of an object. @param object $value The object. @param array $options Array of options. Currently one option is supported: $options['object']['method']. It is a object's method which will return it's string representation @return string The dumped string.
[ "Generate", "a", "string", "representation", "of", "an", "object", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Util/Text.php#L208-L228
train
kahlan/kahlan
src/Util/Text.php
Text.dump
public static function dump($value, $quote = '"') { if (is_bool($value)) { return $value ? 'true' : 'false'; } if (is_null($value)) { return 'null'; } if (!$quote || !is_string($value)) { return (string) $value; } if ($quote === '"') { return $quote . static::_dump($value). $quote; } return $quote . addcslashes($value, $quote) . $quote; }
php
public static function dump($value, $quote = '"') { if (is_bool($value)) { return $value ? 'true' : 'false'; } if (is_null($value)) { return 'null'; } if (!$quote || !is_string($value)) { return (string) $value; } if ($quote === '"') { return $quote . static::_dump($value). $quote; } return $quote . addcslashes($value, $quote) . $quote; }
[ "public", "static", "function", "dump", "(", "$", "value", ",", "$", "quote", "=", "'\"'", ")", "{", "if", "(", "is_bool", "(", "$", "value", ")", ")", "{", "return", "$", "value", "?", "'true'", ":", "'false'", ";", "}", "if", "(", "is_null", "(...
Dump some scalar data using a string representation @param mixed $value The scalar data to dump @param string $quote The quote character to use, default is " @return string The dumped string.
[ "Dump", "some", "scalar", "data", "using", "a", "string", "representation" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Util/Text.php#L238-L253
train
kahlan/kahlan
src/Util/Text.php
Text._dump
protected static function _dump($string) { $es = ['0', 'x07', 'x08', 't', 'n', 'v', 'f', 'r']; $unescaped = ''; $chars = str_split($string); foreach ($chars as $char) { if ($char === '') { continue; } $value = ord($char); if ($value >= 7 && $value <= 13) { $unescaped .= '\\' . $es[$value - 6]; } elseif ($char === '"' || $char === '$' || $char === '\\') { $unescaped .= '\\' . $char; } else { $unescaped .= $char; } } return $unescaped; }
php
protected static function _dump($string) { $es = ['0', 'x07', 'x08', 't', 'n', 'v', 'f', 'r']; $unescaped = ''; $chars = str_split($string); foreach ($chars as $char) { if ($char === '') { continue; } $value = ord($char); if ($value >= 7 && $value <= 13) { $unescaped .= '\\' . $es[$value - 6]; } elseif ($char === '"' || $char === '$' || $char === '\\') { $unescaped .= '\\' . $char; } else { $unescaped .= $char; } } return $unescaped; }
[ "protected", "static", "function", "_dump", "(", "$", "string", ")", "{", "$", "es", "=", "[", "'0'", ",", "'x07'", ",", "'x08'", ",", "'t'", ",", "'n'", ",", "'v'", ",", "'f'", ",", "'r'", "]", ";", "$", "unescaped", "=", "''", ";", "$", "char...
Expands escape sequences and escape special chars in a string. @param string $string A string which contain escape sequence. @return string A valid double quotable string.
[ "Expands", "escape", "sequences", "and", "escape", "special", "chars", "in", "a", "string", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Util/Text.php#L261-L280
train
kahlan/kahlan
src/Reporters.php
Reporters.add
public function add($name, $reporter) { if (!is_object($reporter)) { throw new Exception("Error, reporter must be an object."); } $this->_reporters[$name] = $reporter; }
php
public function add($name, $reporter) { if (!is_object($reporter)) { throw new Exception("Error, reporter must be an object."); } $this->_reporters[$name] = $reporter; }
[ "public", "function", "add", "(", "$", "name", ",", "$", "reporter", ")", "{", "if", "(", "!", "is_object", "(", "$", "reporter", ")", ")", "{", "throw", "new", "Exception", "(", "\"Error, reporter must be an object.\"", ")", ";", "}", "$", "this", "->",...
Adds a reporter @param string $name The reporter name. @param object $reporter A reporter. @return object|boolean The added reporter instance or `false` on failure.
[ "Adds", "a", "reporter" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporters.php#L25-L31
train
kahlan/kahlan
src/Matcher.php
Matcher.get
public static function get($name = null, $target = '') { if (!func_num_args()) { return static::$_matchers; } if ($target === true) { return isset(static::$_matchers[$name]) ? static::$_matchers[$name] : []; } if ($target === '') { if (isset(static::$_matchers[$name][''])) { return static::$_matchers[$name]['']; } throw new Exception("Unexisting default matcher attached to `'{$name}'`."); } if (isset(static::$_matchers[$name][$target])) { return static::$_matchers[$name][$target]; } elseif (isset(static::$_matchers[$name][''])) { return static::$_matchers[$name]['']; } throw new Exception("Unexisting matcher attached to `'{$name}'` for `{$target}`."); }
php
public static function get($name = null, $target = '') { if (!func_num_args()) { return static::$_matchers; } if ($target === true) { return isset(static::$_matchers[$name]) ? static::$_matchers[$name] : []; } if ($target === '') { if (isset(static::$_matchers[$name][''])) { return static::$_matchers[$name]['']; } throw new Exception("Unexisting default matcher attached to `'{$name}'`."); } if (isset(static::$_matchers[$name][$target])) { return static::$_matchers[$name][$target]; } elseif (isset(static::$_matchers[$name][''])) { return static::$_matchers[$name]['']; } throw new Exception("Unexisting matcher attached to `'{$name}'` for `{$target}`."); }
[ "public", "static", "function", "get", "(", "$", "name", "=", "null", ",", "$", "target", "=", "''", ")", "{", "if", "(", "!", "func_num_args", "(", ")", ")", "{", "return", "static", "::", "$", "_matchers", ";", "}", "if", "(", "$", "target", "=...
Returns registered matchers. @param string $name The name of the matcher. @param string $target An optionnal target class name. @return array The registered matchers or a fully-namespaced class name if $name is not null. @throws Exception
[ "Returns", "registered", "matchers", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher.php#L71-L91
train
kahlan/kahlan
src/Matcher.php
Matcher.exists
public static function exists($name, $target = '') { if ($target === true) { return isset(static::$_matchers[$name]); } return isset(static::$_matchers[$name][$target]); }
php
public static function exists($name, $target = '') { if ($target === true) { return isset(static::$_matchers[$name]); } return isset(static::$_matchers[$name][$target]); }
[ "public", "static", "function", "exists", "(", "$", "name", ",", "$", "target", "=", "''", ")", "{", "if", "(", "$", "target", "===", "true", ")", "{", "return", "isset", "(", "static", "::", "$", "_matchers", "[", "$", "name", "]", ")", ";", "}"...
Checks if a matcher is registered. @param string $name The name of the matcher. @param string $target An optional target class name. @return boolean Returns `true` if the matcher exists, `false` otherwise.
[ "Checks", "if", "a", "matcher", "is", "registered", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Matcher.php#L101-L107
train
kahlan/kahlan
src/Arg.php
Arg._describeArg
public static function _describeArg($arg) { if (is_array($arg)) { return sprintf('array[%d]', count($arg)); } if (is_object($arg)) { return sprintf('object[%s]', get_class($arg)); } return Text::toString($arg); }
php
public static function _describeArg($arg) { if (is_array($arg)) { return sprintf('array[%d]', count($arg)); } if (is_object($arg)) { return sprintf('object[%s]', get_class($arg)); } return Text::toString($arg); }
[ "public", "static", "function", "_describeArg", "(", "$", "arg", ")", "{", "if", "(", "is_array", "(", "$", "arg", ")", ")", "{", "return", "sprintf", "(", "'array[%d]'", ",", "count", "(", "$", "arg", ")", ")", ";", "}", "if", "(", "is_object", "(...
Generate an inline string representation of an argument. @param mixed $arg The argument. @return string The dumped string.
[ "Generate", "an", "inline", "string", "representation", "of", "an", "argument", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Arg.php#L165-L175
train
kahlan/kahlan
spec/Mock/Patcher.php
Patcher.findFile
public function findFile($loader, $class, $file) { $args = func_get_args(); $self = isset($this) ? $this : get_called_class(); if ($pointcut = Pointcut::before(__METHOD__, $self, $args)) { return $pointcut($args, $self); } return $file; }
php
public function findFile($loader, $class, $file) { $args = func_get_args(); $self = isset($this) ? $this : get_called_class(); if ($pointcut = Pointcut::before(__METHOD__, $self, $args)) { return $pointcut($args, $self); } return $file; }
[ "public", "function", "findFile", "(", "$", "loader", ",", "$", "class", ",", "$", "file", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "self", "=", "isset", "(", "$", "this", ")", "?", "$", "this", ":", "get_called_class", "(",...
The JIT find file patcher. @param object $loader The autloader instance. @param string $class The fully-namespaced class name. @param string $file The correponding finded file path. @return string The patched file path.
[ "The", "JIT", "find", "file", "patcher", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/spec/Mock/Patcher.php#L16-L24
train
kahlan/kahlan
spec/Mock/Patcher.php
Patcher.patchable
public function patchable($class) { $args = func_get_args(); $self = isset($this) ? $this : get_called_class(); if ($pointcut = Pointcut::before(__METHOD__, $self, $args)) { return $pointcut($args, $self); } return true; }
php
public function patchable($class) { $args = func_get_args(); $self = isset($this) ? $this : get_called_class(); if ($pointcut = Pointcut::before(__METHOD__, $self, $args)) { return $pointcut($args, $self); } return true; }
[ "public", "function", "patchable", "(", "$", "class", ")", "{", "$", "args", "=", "func_get_args", "(", ")", ";", "$", "self", "=", "isset", "(", "$", "this", ")", "?", "$", "this", ":", "get_called_class", "(", ")", ";", "if", "(", "$", "pointcut"...
The JIT patchable checker. @param string $class The fully-namespaced class name to check. @return boolean
[ "The", "JIT", "patchable", "checker", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/spec/Mock/Patcher.php#L32-L40
train
kahlan/kahlan
src/Plugin/Stub.php
Stub.method
public function method($path, $closure = null) { if ($this->_needToBePatched) { $layer = Double::classname(); Monkey::patch($this->_reference, $layer); $this->_needToBePatched = false; $this->_reference = $layer; } $reference = $this->_reference; if (!$path) { throw new InvalidArgumentException("Method name can't be empty."); } $names = is_array($path) ? $path : [$path]; $this->_chain = []; $total = count($names); foreach ($names as $index => $name) { if (preg_match('/^::.*/', $name)) { $reference = is_object($reference) ? get_class($reference) : $reference; } $hash = Suite::hash($reference); if (!isset(static::$_registered[$hash])) { static::$_registered[$hash] = new static($reference); } $instance = static::$_registered[$hash]; if (is_object($reference)) { Suite::register(get_class($reference)); } else { Suite::register($reference); } if (!isset($instance->_methods[$name])) { $instance->_methods[$name] = []; $instance->_stubs[$name] = Double::instance(); } $method = new Method([ 'parent' => $this, 'reference' => $reference, 'name' => $name ]); $this->_chain[$name] = $method; array_unshift($instance->_methods[$name], $method); if ($index < $total - 1) { $reference = $instance->_stubs[$name]; $method->andReturn($instance->_stubs[$name]); } } $method = end($this->_chain); if ($closure) { $method->andRun($closure); } return $method; }
php
public function method($path, $closure = null) { if ($this->_needToBePatched) { $layer = Double::classname(); Monkey::patch($this->_reference, $layer); $this->_needToBePatched = false; $this->_reference = $layer; } $reference = $this->_reference; if (!$path) { throw new InvalidArgumentException("Method name can't be empty."); } $names = is_array($path) ? $path : [$path]; $this->_chain = []; $total = count($names); foreach ($names as $index => $name) { if (preg_match('/^::.*/', $name)) { $reference = is_object($reference) ? get_class($reference) : $reference; } $hash = Suite::hash($reference); if (!isset(static::$_registered[$hash])) { static::$_registered[$hash] = new static($reference); } $instance = static::$_registered[$hash]; if (is_object($reference)) { Suite::register(get_class($reference)); } else { Suite::register($reference); } if (!isset($instance->_methods[$name])) { $instance->_methods[$name] = []; $instance->_stubs[$name] = Double::instance(); } $method = new Method([ 'parent' => $this, 'reference' => $reference, 'name' => $name ]); $this->_chain[$name] = $method; array_unshift($instance->_methods[$name], $method); if ($index < $total - 1) { $reference = $instance->_stubs[$name]; $method->andReturn($instance->_stubs[$name]); } } $method = end($this->_chain); if ($closure) { $method->andRun($closure); } return $method; }
[ "public", "function", "method", "(", "$", "path", ",", "$", "closure", "=", "null", ")", "{", "if", "(", "$", "this", "->", "_needToBePatched", ")", "{", "$", "layer", "=", "Double", "::", "classname", "(", ")", ";", "Monkey", "::", "patch", "(", "...
Stubs a method. @param string $path Method name or array of stubs where key are method names and values the stubs. @param string $closure The stub implementation. @return Method[] The created array of method instances. @return Method The stubbed method instance.
[ "Stubs", "a", "method", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub.php#L142-L202
train
kahlan/kahlan
src/Plugin/Stub.php
Stub.where
public function where($requirements = []) { foreach ($requirements as $name => $args) { if (!isset($this->_chain[$name])) { throw new InvalidArgumentException("Unexisting `{$name}` as method as part of the chain definition."); } if (!is_array($args)) { throw new InvalidArgumentException("Argument requirements must be an arrays for `{$name}` method."); } call_user_func_array([$this->_chain[$name], 'with'], $args); } return $this; }
php
public function where($requirements = []) { foreach ($requirements as $name => $args) { if (!isset($this->_chain[$name])) { throw new InvalidArgumentException("Unexisting `{$name}` as method as part of the chain definition."); } if (!is_array($args)) { throw new InvalidArgumentException("Argument requirements must be an arrays for `{$name}` method."); } call_user_func_array([$this->_chain[$name], 'with'], $args); } return $this; }
[ "public", "function", "where", "(", "$", "requirements", "=", "[", "]", ")", "{", "foreach", "(", "$", "requirements", "as", "$", "name", "=>", "$", "args", ")", "{", "if", "(", "!", "isset", "(", "$", "this", "->", "_chain", "[", "$", "name", "]...
Set arguments requirement indexed by method name. @param mixed ... <0,n> Argument(s). @return self
[ "Set", "arguments", "requirement", "indexed", "by", "method", "name", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub.php#L210-L222
train
kahlan/kahlan
src/Plugin/Stub.php
Stub.on
public static function on($reference) { $hash = Suite::hash($reference); if (isset(static::$_registered[$hash])) { return static::$_registered[$hash]; } return static::$_registered[$hash] = new static($reference); }
php
public static function on($reference) { $hash = Suite::hash($reference); if (isset(static::$_registered[$hash])) { return static::$_registered[$hash]; } return static::$_registered[$hash] = new static($reference); }
[ "public", "static", "function", "on", "(", "$", "reference", ")", "{", "$", "hash", "=", "Suite", "::", "hash", "(", "$", "reference", ")", ";", "if", "(", "isset", "(", "static", "::", "$", "_registered", "[", "$", "hash", "]", ")", ")", "{", "r...
Stubs class methods. @param object|string $reference An instance or a fully-namespaced class name. @return self The Stub instance.
[ "Stubs", "class", "methods", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub.php#L230-L237
train
kahlan/kahlan
src/Plugin/Stub.php
Stub.find
public static function find($references, $method = null, $args = null) { $references = (array) $references; $stub = null; foreach ($references as $reference) { $hash = Suite::hash($reference); if (!isset(static::$_registered[$hash])) { continue; } $stubs = static::$_registered[$hash]->methods(); if (!isset($stubs[$method])) { continue; } foreach ($stubs[$method] as $stub) { $call['name'] = $method; $call['args'] = $args; if ($stub->match($call)) { return $stub; } } } return false; }
php
public static function find($references, $method = null, $args = null) { $references = (array) $references; $stub = null; foreach ($references as $reference) { $hash = Suite::hash($reference); if (!isset(static::$_registered[$hash])) { continue; } $stubs = static::$_registered[$hash]->methods(); if (!isset($stubs[$method])) { continue; } foreach ($stubs[$method] as $stub) { $call['name'] = $method; $call['args'] = $args; if ($stub->match($call)) { return $stub; } } } return false; }
[ "public", "static", "function", "find", "(", "$", "references", ",", "$", "method", "=", "null", ",", "$", "args", "=", "null", ")", "{", "$", "references", "=", "(", "array", ")", "$", "references", ";", "$", "stub", "=", "null", ";", "foreach", "...
Finds a stub. @param mixed $references An instance or a fully namespaced class name. or an array of that. @param string $method The method name. @param array $args The required arguments. @return object|null Return the subbed method or `null` if not founded.
[ "Finds", "a", "stub", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub.php#L248-L272
train
kahlan/kahlan
src/Plugin/Stub.php
Stub.reset
public static function reset($reference = null) { if ($reference === null) { static::$_registered = []; Suite::reset(); return; } unset(static::$_registered[Suite::hash($reference)]); }
php
public static function reset($reference = null) { if ($reference === null) { static::$_registered = []; Suite::reset(); return; } unset(static::$_registered[Suite::hash($reference)]); }
[ "public", "static", "function", "reset", "(", "$", "reference", "=", "null", ")", "{", "if", "(", "$", "reference", "===", "null", ")", "{", "static", "::", "$", "_registered", "=", "[", "]", ";", "Suite", "::", "reset", "(", ")", ";", "return", ";...
Clears the registered references. @param string $reference An instance or a fully namespaced class name or `null` to clear all.
[ "Clears", "the", "registered", "references", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub.php#L293-L301
train
kahlan/kahlan
src/Reporter/Bar.php
Bar._progressBar
protected function _progressBar() { if ($this->_current > $this->_total) { return; } $percent = $this->_current / $this->_total; $nb = $percent * $this->_size; $b = str_repeat($this->_chars['bar'], floor($nb)); $i = ''; if ($nb < $this->_size) { $i = str_pad($this->_chars['indicator'], $this->_size - strlen($b)); } $p = floor($percent * 100); $string = Text::insert($this->_format, compact('p', 'b', 'i')); $this->write("\r" . $string, $this->_color); }
php
protected function _progressBar() { if ($this->_current > $this->_total) { return; } $percent = $this->_current / $this->_total; $nb = $percent * $this->_size; $b = str_repeat($this->_chars['bar'], floor($nb)); $i = ''; if ($nb < $this->_size) { $i = str_pad($this->_chars['indicator'], $this->_size - strlen($b)); } $p = floor($percent * 100); $string = Text::insert($this->_format, compact('p', 'b', 'i')); $this->write("\r" . $string, $this->_color); }
[ "protected", "function", "_progressBar", "(", ")", "{", "if", "(", "$", "this", "->", "_current", ">", "$", "this", "->", "_total", ")", "{", "return", ";", "}", "$", "percent", "=", "$", "this", "->", "_current", "/", "$", "this", "->", "_total", ...
Ouputs the progress bar to STDOUT.
[ "Ouputs", "the", "progress", "bar", "to", "STDOUT", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Bar.php#L107-L128
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger.trace
public static function trace($options = []) { $defaults = [ 'trace' => [], 'array' => false ]; $options += $defaults; $back = []; $backtrace = static::backtrace($options); foreach ($backtrace as $trace) { $back[] = static::_traceToString($trace); } return $options['array'] ? $back : join("\n", $back); }
php
public static function trace($options = []) { $defaults = [ 'trace' => [], 'array' => false ]; $options += $defaults; $back = []; $backtrace = static::backtrace($options); foreach ($backtrace as $trace) { $back[] = static::_traceToString($trace); } return $options['array'] ? $back : join("\n", $back); }
[ "public", "static", "function", "trace", "(", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'trace'", "=>", "[", "]", ",", "'array'", "=>", "false", "]", ";", "$", "options", "+=", "$", "defaults", ";", "$", "back", "=", "[...
Gets a backtrace string or string array based on the supplied options. @param array $options Format for outputting stack trace. Available options are: - `'start'` _integer_: The depth to start with. - `'depth'` _integer_: The maximum depth of the trace. - `'message'` _string_ : Either `null` for default message or a string. - `'trace'` _array_: A trace to use instead of generating one. - `'array'` _array_: Returns an string array instead of a plain string. @return array The formatted backtrace.
[ "Gets", "a", "backtrace", "string", "or", "string", "array", "based", "on", "the", "supplied", "options", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L28-L42
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger._traceToString
protected static function _traceToString($trace) { $loader = static::loader(); if (!empty($trace['class'])) { $trace['function'] = $trace['class'] . '::' . $trace['function'] . '()'; } else { $line = static::_line($trace); $trace['line'] = $line !== $trace['line'] ? $line . ' to ' . $trace['line'] : $trace['line']; } if (preg_match("/eval\(\)'d code/", $trace['file']) && $trace['class'] && $loader) { $trace['file'] = $loader->findFile($trace['class']); } return $trace['function'] .' - ' . $trace['file'] . ', line ' . $trace['line']; }
php
protected static function _traceToString($trace) { $loader = static::loader(); if (!empty($trace['class'])) { $trace['function'] = $trace['class'] . '::' . $trace['function'] . '()'; } else { $line = static::_line($trace); $trace['line'] = $line !== $trace['line'] ? $line . ' to ' . $trace['line'] : $trace['line']; } if (preg_match("/eval\(\)'d code/", $trace['file']) && $trace['class'] && $loader) { $trace['file'] = $loader->findFile($trace['class']); } return $trace['function'] .' - ' . $trace['file'] . ', line ' . $trace['line']; }
[ "protected", "static", "function", "_traceToString", "(", "$", "trace", ")", "{", "$", "loader", "=", "static", "::", "loader", "(", ")", ";", "if", "(", "!", "empty", "(", "$", "trace", "[", "'class'", "]", ")", ")", "{", "$", "trace", "[", "'func...
Gets a string representation of a trace. @param array $trace A trace array. @return string The string representation of a trace.
[ "Gets", "a", "string", "representation", "of", "a", "trace", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L50-L65
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger.backtrace
public static function backtrace($options = []) { $defaults = [ 'trace' => [], 'start' => 0, 'depth' => 0, 'object' => false, 'args' => false ]; $options += $defaults; $mask = $options['args'] ? 0 : DEBUG_BACKTRACE_IGNORE_ARGS; $mask = $options['object'] ? $mask | DEBUG_BACKTRACE_PROVIDE_OBJECT : $mask; $backtrace = static::normalize($options['trace'] ?: debug_backtrace($mask)); $traceDefaults = [ 'line' => '?', 'file' => '[internal]', 'class' => null, 'function' => '[NA]' ]; $back = []; $ignoreFunctions = ['call_user_func_array', 'trigger_error']; foreach ($backtrace as $i => $trace) { $trace += $traceDefaults; if (strpos($trace['function'], 'Closure$') === 0 || strpos($trace['function'], '{closure}') !== false || in_array($trace['function'], $ignoreFunctions)) { continue; } $back[] = $trace; } $count = count($back); return array_splice($back, $options['start'], $options['depth'] ?: $count); }
php
public static function backtrace($options = []) { $defaults = [ 'trace' => [], 'start' => 0, 'depth' => 0, 'object' => false, 'args' => false ]; $options += $defaults; $mask = $options['args'] ? 0 : DEBUG_BACKTRACE_IGNORE_ARGS; $mask = $options['object'] ? $mask | DEBUG_BACKTRACE_PROVIDE_OBJECT : $mask; $backtrace = static::normalize($options['trace'] ?: debug_backtrace($mask)); $traceDefaults = [ 'line' => '?', 'file' => '[internal]', 'class' => null, 'function' => '[NA]' ]; $back = []; $ignoreFunctions = ['call_user_func_array', 'trigger_error']; foreach ($backtrace as $i => $trace) { $trace += $traceDefaults; if (strpos($trace['function'], 'Closure$') === 0 || strpos($trace['function'], '{closure}') !== false || in_array($trace['function'], $ignoreFunctions)) { continue; } $back[] = $trace; } $count = count($back); return array_splice($back, $options['start'], $options['depth'] ?: $count); }
[ "public", "static", "function", "backtrace", "(", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'trace'", "=>", "[", "]", ",", "'start'", "=>", "0", ",", "'depth'", "=>", "0", ",", "'object'", "=>", "false", ",", "'args'", "=...
Return a backtrace array based on the supplied options. @param array $options Format for outputting stack trace. Available options are: - `'start'`: The depth to start with. - `'depth'`: The maximum depth of the trace. - `'message'`: Either `null` for default message or a string. - `'trace'`: A trace to use instead of generating one. @return array The backtrace array.
[ "Return", "a", "backtrace", "array", "based", "on", "the", "supplied", "options", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L77-L115
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger.normalize
public static function normalize($backtrace) { if (!static::isThrowable($backtrace)) { return $backtrace; } return array_merge([[ 'function' => '[NA]', 'file' => $backtrace->getFile(), 'line' => $backtrace->getLine(), 'args' => [] ]], $backtrace->getTrace()); }
php
public static function normalize($backtrace) { if (!static::isThrowable($backtrace)) { return $backtrace; } return array_merge([[ 'function' => '[NA]', 'file' => $backtrace->getFile(), 'line' => $backtrace->getLine(), 'args' => [] ]], $backtrace->getTrace()); }
[ "public", "static", "function", "normalize", "(", "$", "backtrace", ")", "{", "if", "(", "!", "static", "::", "isThrowable", "(", "$", "backtrace", ")", ")", "{", "return", "$", "backtrace", ";", "}", "return", "array_merge", "(", "[", "[", "'function'",...
Normalises a backtrace. @param array|object $backtrace A backtrace array or an exception instance. @return array A backtrace array.
[ "Normalises", "a", "backtrace", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L123-L134
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger.message
public static function message($backtrace) { if (static::isThrowable($backtrace)) { $name = get_class($backtrace); $code = $backtrace->getCode(); return "`{$name}` Code({$code}): " . $backtrace->getMessage(); } elseif (isset($backtrace['message'])) { $code = isset($backtrace['code']) ? $backtrace['code'] : 0; $name = static::errorType($code); return "`{$name}` Code({$code}): " . $backtrace['message']; } }
php
public static function message($backtrace) { if (static::isThrowable($backtrace)) { $name = get_class($backtrace); $code = $backtrace->getCode(); return "`{$name}` Code({$code}): " . $backtrace->getMessage(); } elseif (isset($backtrace['message'])) { $code = isset($backtrace['code']) ? $backtrace['code'] : 0; $name = static::errorType($code); return "`{$name}` Code({$code}): " . $backtrace['message']; } }
[ "public", "static", "function", "message", "(", "$", "backtrace", ")", "{", "if", "(", "static", "::", "isThrowable", "(", "$", "backtrace", ")", ")", "{", "$", "name", "=", "get_class", "(", "$", "backtrace", ")", ";", "$", "code", "=", "$", "backtr...
Generates a string message from a backtrace array. @param array|object $backtrace A backtrace array or an exception instance. @return string The string message.
[ "Generates", "a", "string", "message", "from", "a", "backtrace", "array", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L156-L167
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger._line
protected static function _line($trace) { $path = $trace['file']; $callLine = $trace['line']; if (!file_exists($path)) { return; } $file = file_get_contents($path); if (($i = static::_findPos($file, $callLine)) === null) { return; } $line = $callLine; $brackets = 0; while ($i >= 0) { if ($file[$i] === ')') { $brackets--; } elseif ($file[$i] === '(') { $brackets++; } elseif ($file[$i] === "\n") { $line--; } if ($brackets > 0) { return $line; } $i--; } }
php
protected static function _line($trace) { $path = $trace['file']; $callLine = $trace['line']; if (!file_exists($path)) { return; } $file = file_get_contents($path); if (($i = static::_findPos($file, $callLine)) === null) { return; } $line = $callLine; $brackets = 0; while ($i >= 0) { if ($file[$i] === ')') { $brackets--; } elseif ($file[$i] === '(') { $brackets++; } elseif ($file[$i] === "\n") { $line--; } if ($brackets > 0) { return $line; } $i--; } }
[ "protected", "static", "function", "_line", "(", "$", "trace", ")", "{", "$", "path", "=", "$", "trace", "[", "'file'", "]", ";", "$", "callLine", "=", "$", "trace", "[", "'line'", "]", ";", "if", "(", "!", "file_exists", "(", "$", "path", ")", "...
Locates a line number from a trace. @param array $trace A trace data. @return mixed Returns the line number where the method called is defined.
[ "Locates", "a", "line", "number", "from", "a", "trace", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L175-L202
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger._findPos
protected static function _findPos($file, $callLine) { $len = strlen($file); $line = 1; $i = 0; while ($i < $len) { if ($file[$i] === "\n") { $line++; } if ($line === $callLine) { return $i; } $i++; } }
php
protected static function _findPos($file, $callLine) { $len = strlen($file); $line = 1; $i = 0; while ($i < $len) { if ($file[$i] === "\n") { $line++; } if ($line === $callLine) { return $i; } $i++; } }
[ "protected", "static", "function", "_findPos", "(", "$", "file", ",", "$", "callLine", ")", "{", "$", "len", "=", "strlen", "(", "$", "file", ")", ";", "$", "line", "=", "1", ";", "$", "i", "=", "0", ";", "while", "(", "$", "i", "<", "$", "le...
Return the first character position of a specific line in a file. @param string $file A file content. @param integer $callLine The number of line to find. @return mixed Returns the character position or null if not found.
[ "Return", "the", "first", "character", "position", "of", "a", "specific", "line", "in", "a", "file", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L211-L226
train
kahlan/kahlan
src/Analysis/Debugger.php
Debugger.focus
public static function focus($pattern, $backtrace, $depth = null, $maxLookup = 10) { if (!$pattern) { return $backtrace; } $i = 0; $start = 0; $found = false; while ($i < $maxLookup && isset($backtrace[$i])) { if (isset($backtrace[$i]['file'])) { $start = $start ?: $i; if (preg_match('~^' . $pattern . '$~', $backtrace[$i]['file'])) { $found = true; break; } } $i++; } return array_slice(array_slice($backtrace, $found ? $i : $start), 0, $depth); }
php
public static function focus($pattern, $backtrace, $depth = null, $maxLookup = 10) { if (!$pattern) { return $backtrace; } $i = 0; $start = 0; $found = false; while ($i < $maxLookup && isset($backtrace[$i])) { if (isset($backtrace[$i]['file'])) { $start = $start ?: $i; if (preg_match('~^' . $pattern . '$~', $backtrace[$i]['file'])) { $found = true; break; } } $i++; } return array_slice(array_slice($backtrace, $found ? $i : $start), 0, $depth); }
[ "public", "static", "function", "focus", "(", "$", "pattern", ",", "$", "backtrace", ",", "$", "depth", "=", "null", ",", "$", "maxLookup", "=", "10", ")", "{", "if", "(", "!", "$", "pattern", ")", "{", "return", "$", "backtrace", ";", "}", "$", ...
Unstack all traces up to a trace which match a filename regexp. @param array $pattern The regexp to match on. @param array $backtrace The backtrace. @param array $depth Number of traces to keep. @param int $maxLookup The maximum lookup window. @return array A cleaned backtrace.
[ "Unstack", "all", "traces", "up", "to", "a", "trace", "which", "match", "a", "filename", "regexp", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Analysis/Debugger.php#L239-L260
train
kahlan/kahlan
src/Reporter/Dot.php
Dot._write
protected function _write($string, $options = null) { $this->write($string, $options); $this->_counter++; if ($this->_counter % $this->_dotWidth === 0) { $counter = min($this->_counter, $this->_total); $percent = min(floor(($counter * 100) / $this->_total), 100) . '%'; $this->write(str_pad($counter, strlen($this->_total) + 1, ' ', STR_PAD_LEFT)); $this->write(' / ' . $this->_total); $this->write(' (' . str_pad($percent, 4, ' ', STR_PAD_LEFT) . ")\n"); } }
php
protected function _write($string, $options = null) { $this->write($string, $options); $this->_counter++; if ($this->_counter % $this->_dotWidth === 0) { $counter = min($this->_counter, $this->_total); $percent = min(floor(($counter * 100) / $this->_total), 100) . '%'; $this->write(str_pad($counter, strlen($this->_total) + 1, ' ', STR_PAD_LEFT)); $this->write(' / ' . $this->_total); $this->write(' (' . str_pad($percent, 4, ' ', STR_PAD_LEFT) . ")\n"); } }
[ "protected", "function", "_write", "(", "$", "string", ",", "$", "options", "=", "null", ")", "{", "$", "this", "->", "write", "(", "$", "string", ",", "$", "options", ")", ";", "$", "this", "->", "_counter", "++", ";", "if", "(", "$", "this", "-...
Outputs the string message in the console. @param string $string The string message. @param array|string $options The color options.
[ "Outputs", "the", "string", "message", "in", "the", "console", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Dot.php#L112-L124
train
kahlan/kahlan
src/Suite.php
Suite._errorHandler
protected function _errorHandler($enable, $options = []) { $defaults = ['handler' => null]; $options += $defaults; if (!$enable) { return restore_error_handler(); } $handler = function ($code, $message, $file, $line = 0, $args = []) { if (error_reporting() === 0) { return; } $trace = debug_backtrace(); $trace = array_slice($trace, 1, count($trace)); $message = "`" . Debugger::errorType($code) . "` {$message}"; $code = 0; $exception = compact('code', 'message', 'file', 'line', 'trace'); throw new PhpErrorException($exception); }; $options['handler'] = $options['handler'] ?: $handler; set_error_handler($options['handler'], error_reporting()); }
php
protected function _errorHandler($enable, $options = []) { $defaults = ['handler' => null]; $options += $defaults; if (!$enable) { return restore_error_handler(); } $handler = function ($code, $message, $file, $line = 0, $args = []) { if (error_reporting() === 0) { return; } $trace = debug_backtrace(); $trace = array_slice($trace, 1, count($trace)); $message = "`" . Debugger::errorType($code) . "` {$message}"; $code = 0; $exception = compact('code', 'message', 'file', 'line', 'trace'); throw new PhpErrorException($exception); }; $options['handler'] = $options['handler'] ?: $handler; set_error_handler($options['handler'], error_reporting()); }
[ "protected", "function", "_errorHandler", "(", "$", "enable", ",", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'handler'", "=>", "null", "]", ";", "$", "options", "+=", "$", "defaults", ";", "if", "(", "!", "$", "enable", "...
Overrides the default error handler @param boolean $enable If `true` override the default error handler, if `false` restore the default handler. @param array $options An options array. Available options are: - 'handler': An error handler closure.
[ "Overrides", "the", "default", "error", "handler" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Suite.php#L141-L161
train
kahlan/kahlan
src/Suite.php
Suite.run
public function run($options = []) { $defaults = [ 'reporters' => null, 'autoclear' => [], 'ff' => 0, 'part' => '1/1' ]; $options += $defaults; $this->_reporters = $options['reporters']; $this->_autoclear = (array) $options['autoclear']; $this->_ff = $options['ff']; list($index, $total) = explode('/', $options['part']) + [null, null]; $this->root()->partition($index, $total); $this->report('start', ['total' => $this->active()]); $this->_errorHandler(true, $options); $passed = $this->root()->process(); $this->_errorHandler(false); $this->summary()->memoryUsage(memory_get_peak_usage()); $this->report('end', $this->summary()); $this->_status = $passed ? 0 : -1; return $passed; }
php
public function run($options = []) { $defaults = [ 'reporters' => null, 'autoclear' => [], 'ff' => 0, 'part' => '1/1' ]; $options += $defaults; $this->_reporters = $options['reporters']; $this->_autoclear = (array) $options['autoclear']; $this->_ff = $options['ff']; list($index, $total) = explode('/', $options['part']) + [null, null]; $this->root()->partition($index, $total); $this->report('start', ['total' => $this->active()]); $this->_errorHandler(true, $options); $passed = $this->root()->process(); $this->_errorHandler(false); $this->summary()->memoryUsage(memory_get_peak_usage()); $this->report('end', $this->summary()); $this->_status = $passed ? 0 : -1; return $passed; }
[ "public", "function", "run", "(", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'reporters'", "=>", "null", ",", "'autoclear'", "=>", "[", "]", ",", "'ff'", "=>", "0", ",", "'part'", "=>", "'1/1'", "]", ";", "$", "options", ...
Runs all specs. @param array $options Run options. @return boolean The result array. @throws Exception
[ "Runs", "all", "specs", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Suite.php#L191-L222
train
kahlan/kahlan
src/Suite.php
Suite.runBlock
public function runBlock($block, $closure, $type) { return Filters::run($this, 'runBlock', [$block, $closure, $type], function ($next, $block, $closure, $type) { return call_user_func_array($closure, []); }); }
php
public function runBlock($block, $closure, $type) { return Filters::run($this, 'runBlock', [$block, $closure, $type], function ($next, $block, $closure, $type) { return call_user_func_array($closure, []); }); }
[ "public", "function", "runBlock", "(", "$", "block", ",", "$", "closure", ",", "$", "type", ")", "{", "return", "Filters", "::", "run", "(", "$", "this", ",", "'runBlock'", ",", "[", "$", "block", ",", "$", "closure", ",", "$", "type", "]", ",", ...
Run a block's closure. @param Block $block The block instance. @param Closure $closure The closure. @param string $type The closure type. @return mixed
[ "Run", "a", "block", "s", "closure", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Suite.php#L232-L237
train
kahlan/kahlan
src/Suite.php
Suite.active
public function active() { $stats = $this->root()->stats(); return $this->root()->focused() ? $stats['focused'] : $stats['normal']; }
php
public function active() { $stats = $this->root()->stats(); return $this->root()->focused() ? $stats['focused'] : $stats['normal']; }
[ "public", "function", "active", "(", ")", "{", "$", "stats", "=", "$", "this", "->", "root", "(", ")", "->", "stats", "(", ")", ";", "return", "$", "this", "->", "root", "(", ")", "->", "focused", "(", ")", "?", "$", "stats", "[", "'focused'", ...
Gets number of active specs. @return integer
[ "Gets", "number", "of", "active", "specs", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Suite.php#L265-L269
train
kahlan/kahlan
src/Suite.php
Suite.autoclear
public function autoclear() { foreach ($this->_autoclear as $plugin) { if (is_object($plugin)) { if (method_exists($plugin, 'clear')) { $plugin->clear(); } } elseif (method_exists($plugin, 'reset')) { $plugin::reset(); } } }
php
public function autoclear() { foreach ($this->_autoclear as $plugin) { if (is_object($plugin)) { if (method_exists($plugin, 'clear')) { $plugin->clear(); } } elseif (method_exists($plugin, 'reset')) { $plugin::reset(); } } }
[ "public", "function", "autoclear", "(", ")", "{", "foreach", "(", "$", "this", "->", "_autoclear", "as", "$", "plugin", ")", "{", "if", "(", "is_object", "(", "$", "plugin", ")", ")", "{", "if", "(", "method_exists", "(", "$", "plugin", ",", "'clear'...
Autoclears plugins.
[ "Autoclears", "plugins", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Suite.php#L317-L328
train
kahlan/kahlan
src/Suite.php
Suite.hash
public static function hash($reference) { if (is_object($reference)) { return spl_object_hash($reference); } if (is_string($reference)) { return $reference; } throw new InvalidArgumentException("Error, the passed argument is not hashable."); }
php
public static function hash($reference) { if (is_object($reference)) { return spl_object_hash($reference); } if (is_string($reference)) { return $reference; } throw new InvalidArgumentException("Error, the passed argument is not hashable."); }
[ "public", "static", "function", "hash", "(", "$", "reference", ")", "{", "if", "(", "is_object", "(", "$", "reference", ")", ")", "{", "return", "spl_object_hash", "(", "$", "reference", ")", ";", "}", "if", "(", "is_string", "(", "$", "reference", ")"...
Generates a hash from an instance or a string. @param mixed $reference An instance or a fully namespaced class name. @return string A string hash. @throws InvalidArgumentException
[ "Generates", "a", "hash", "from", "an", "instance", "or", "a", "string", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Suite.php#L346-L355
train
kahlan/kahlan
src/Scope/Group.php
Group.xcontext
public function xcontext($message, $closure, $timeout = null) { return $this->_block->context($message, $closure, $timeout, 'exclude'); }
php
public function xcontext($message, $closure, $timeout = null) { return $this->_block->context($message, $closure, $timeout, 'exclude'); }
[ "public", "function", "xcontext", "(", "$", "message", ",", "$", "closure", ",", "$", "timeout", "=", "null", ")", "{", "return", "$", "this", "->", "_block", "->", "context", "(", "$", "message", ",", "$", "closure", ",", "$", "timeout", ",", "'excl...
Comments out a context related spec. @param string $message Description message. @param Closure $closure A test case closure. @return
[ "Comments", "out", "a", "context", "related", "spec", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Scope/Group.php#L71-L74
train
kahlan/kahlan
src/Scope/Group.php
Group.xit
public function xit($message, $closure = null, $timeout = null) { return $this->_block->it($message, $closure, $timeout, 'exclude'); }
php
public function xit($message, $closure = null, $timeout = null) { return $this->_block->it($message, $closure, $timeout, 'exclude'); }
[ "public", "function", "xit", "(", "$", "message", ",", "$", "closure", "=", "null", ",", "$", "timeout", "=", "null", ")", "{", "return", "$", "this", "->", "_block", "->", "it", "(", "$", "message", ",", "$", "closure", ",", "$", "timeout", ",", ...
Comments out a spec. @param string|Closure $message Description message or a test closure. @param Closure|null $closure A test case closure or `null`. @return
[ "Comments", "out", "a", "spec", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Scope/Group.php#L84-L87
train
kahlan/kahlan
src/Scope/Group.php
Group.fcontext
public function fcontext($message, $closure, $timeout = null) { return $this->_block->context($message, $closure, $timeout, 'focus'); }
php
public function fcontext($message, $closure, $timeout = null) { return $this->_block->context($message, $closure, $timeout, 'focus'); }
[ "public", "function", "fcontext", "(", "$", "message", ",", "$", "closure", ",", "$", "timeout", "=", "null", ")", "{", "return", "$", "this", "->", "_block", "->", "context", "(", "$", "message", ",", "$", "closure", ",", "$", "timeout", ",", "'focu...
Adds an focused context related spec. @param string $message Description message. @param Closure $closure A test case closure. @return Group
[ "Adds", "an", "focused", "context", "related", "spec", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Scope/Group.php#L110-L113
train
kahlan/kahlan
src/Scope/Group.php
Group.fit
public function fit($message, $closure = null, $timeout = null) { return $this->_block->it($message, $closure, $timeout, 'focus'); }
php
public function fit($message, $closure = null, $timeout = null) { return $this->_block->it($message, $closure, $timeout, 'focus'); }
[ "public", "function", "fit", "(", "$", "message", ",", "$", "closure", "=", "null", ",", "$", "timeout", "=", "null", ")", "{", "return", "$", "this", "->", "_block", "->", "it", "(", "$", "message", ",", "$", "closure", ",", "$", "timeout", ",", ...
Adds an focused spec. @param string|Closure $message Description message or a test closure. @param Closure|null $closure A test case closure or `null`. @return Specification
[ "Adds", "an", "focused", "spec", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Scope/Group.php#L123-L126
train
kahlan/kahlan
src/Jit/Patchers.php
Patchers.add
public function add($name, $patcher) { if (!is_object($patcher)) { return false; } return $this->_patchers[$name] = $patcher; }
php
public function add($name, $patcher) { if (!is_object($patcher)) { return false; } return $this->_patchers[$name] = $patcher; }
[ "public", "function", "add", "(", "$", "name", ",", "$", "patcher", ")", "{", "if", "(", "!", "is_object", "(", "$", "patcher", ")", ")", "{", "return", "false", ";", "}", "return", "$", "this", "->", "_patchers", "[", "$", "name", "]", "=", "$",...
Adds a patcher. @param string $name The patcher name. @param object $patcher A patcher. @return object|boolean The added patcher instance or `false` on failure.
[ "Adds", "a", "patcher", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Patchers.php#L22-L28
train
kahlan/kahlan
src/Jit/Patchers.php
Patchers.findFile
public function findFile($loader, $class, $file) { foreach ($this->_patchers as $patcher) { $file = $patcher->findFile($loader, $class, $file); } return $file; }
php
public function findFile($loader, $class, $file) { foreach ($this->_patchers as $patcher) { $file = $patcher->findFile($loader, $class, $file); } return $file; }
[ "public", "function", "findFile", "(", "$", "loader", ",", "$", "class", ",", "$", "file", ")", "{", "foreach", "(", "$", "this", "->", "_patchers", "as", "$", "patcher", ")", "{", "$", "file", "=", "$", "patcher", "->", "findFile", "(", "$", "load...
Runs file loader patchers. @param string $path The original path of the file. @param string The patched file path to load.
[ "Runs", "file", "loader", "patchers", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Patchers.php#L80-L86
train
kahlan/kahlan
src/Jit/Patchers.php
Patchers.process
public function process($code, $path = null) { if (!$code) { return ''; } $nodes = Parser::parse($code, ['path' => $path]); foreach ($this->_patchers as $patcher) { $patcher->process($nodes, $path); } return Parser::unparse($nodes); }
php
public function process($code, $path = null) { if (!$code) { return ''; } $nodes = Parser::parse($code, ['path' => $path]); foreach ($this->_patchers as $patcher) { $patcher->process($nodes, $path); } return Parser::unparse($nodes); }
[ "public", "function", "process", "(", "$", "code", ",", "$", "path", "=", "null", ")", "{", "if", "(", "!", "$", "code", ")", "{", "return", "''", ";", "}", "$", "nodes", "=", "Parser", "::", "parse", "(", "$", "code", ",", "[", "'path'", "=>",...
Runs file patchers. @param string $code The source code to process. @param string $path The file path of the source code. @return string The patched source code.
[ "Runs", "file", "patchers", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/Patchers.php#L111-L121
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.patch
public function patch($options = []) { $defaults = [ 'patchers' => null, 'exclude' => [], 'include' => ['*'], 'watch' => [], 'cachePath' => rtrim(sys_get_temp_dir(), DS) . DS . 'jit', 'clearCache' => false ]; $options += $defaults; $this->_patchers = new Patchers(); $this->_cachePath = rtrim($options['cachePath'], DS); $this->_exclude = (array) $options['exclude']; $this->_exclude[] = 'jit\\'; $this->_include = (array) $options['include']; if ($options['clearCache']) { $this->clearCache(); } if ($options['watch']) { $this->watch($options['watch']); } }
php
public function patch($options = []) { $defaults = [ 'patchers' => null, 'exclude' => [], 'include' => ['*'], 'watch' => [], 'cachePath' => rtrim(sys_get_temp_dir(), DS) . DS . 'jit', 'clearCache' => false ]; $options += $defaults; $this->_patchers = new Patchers(); $this->_cachePath = rtrim($options['cachePath'], DS); $this->_exclude = (array) $options['exclude']; $this->_exclude[] = 'jit\\'; $this->_include = (array) $options['include']; if ($options['clearCache']) { $this->clearCache(); } if ($options['watch']) { $this->watch($options['watch']); } }
[ "public", "function", "patch", "(", "$", "options", "=", "[", "]", ")", "{", "$", "defaults", "=", "[", "'patchers'", "=>", "null", ",", "'exclude'", "=>", "[", "]", ",", "'include'", "=>", "[", "'*'", "]", ",", "'watch'", "=>", "[", "]", ",", "'...
Apply JIT code patching @param array $options Options for the constructor.
[ "Apply", "JIT", "code", "patching" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L68-L93
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.watch
public function watch($files) { $files = (array) $files; foreach ($files as $file) { $path = realpath($file); $this->_watched[$path] = $path; } $this->refreshWatched(); }
php
public function watch($files) { $files = (array) $files; foreach ($files as $file) { $path = realpath($file); $this->_watched[$path] = $path; } $this->refreshWatched(); }
[ "public", "function", "watch", "(", "$", "files", ")", "{", "$", "files", "=", "(", "array", ")", "$", "files", ";", "foreach", "(", "$", "files", "as", "$", "file", ")", "{", "$", "path", "=", "realpath", "(", "$", "file", ")", ";", "$", "this...
Sets some file to watch. When a watched file is modified, any cached file are invalidated. @param $files The array of file paths to watch.
[ "Sets", "some", "file", "to", "watch", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L127-L136
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.refreshWatched
public function refreshWatched() { $timestamps = [0]; foreach ($this->_watched as $path) { $timestamps[] = filemtime($path); } $this->_watchedTimestamp = max($timestamps); }
php
public function refreshWatched() { $timestamps = [0]; foreach ($this->_watched as $path) { $timestamps[] = filemtime($path); } $this->_watchedTimestamp = max($timestamps); }
[ "public", "function", "refreshWatched", "(", ")", "{", "$", "timestamps", "=", "[", "0", "]", ";", "foreach", "(", "$", "this", "->", "_watched", "as", "$", "path", ")", "{", "$", "timestamps", "[", "]", "=", "filemtime", "(", "$", "path", ")", ";"...
Refresh watched file timestamps
[ "Refresh", "watched", "file", "timestamps" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L167-L174
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.allowed
public function allowed($class) { foreach ($this->_exclude as $namespace) { if (strpos($class, $namespace) === 0) { return false; } } if ($this->_include === ['*']) { return true; } foreach ($this->_include as $namespace) { if (strpos($class, $namespace) === 0) { return true; } } return false; }
php
public function allowed($class) { foreach ($this->_exclude as $namespace) { if (strpos($class, $namespace) === 0) { return false; } } if ($this->_include === ['*']) { return true; } foreach ($this->_include as $namespace) { if (strpos($class, $namespace) === 0) { return true; } } return false; }
[ "public", "function", "allowed", "(", "$", "class", ")", "{", "foreach", "(", "$", "this", "->", "_exclude", "as", "$", "namespace", ")", "{", "if", "(", "strpos", "(", "$", "class", ",", "$", "namespace", ")", "===", "0", ")", "{", "return", "fals...
Checks if a class is allowed to be patched. @param string $class The name of the class to check. @return boolean Returns `true` if the class is allowed to be patched, `false` otherwise.
[ "Checks", "if", "a", "class", "is", "allowed", "to", "be", "patched", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L206-L222
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.cached
public function cached($file) { if (!$cachePath = $this->cachePath()) { return false; } $path = $cachePath . DS . ltrim(preg_replace('~:~', '', $file), DS); if (!@file_exists($path)) { return false; } $timestamp = filemtime($path); if ($timestamp > filemtime($file) && $timestamp > $this->_watchedTimestamp) { return $path; } return false; }
php
public function cached($file) { if (!$cachePath = $this->cachePath()) { return false; } $path = $cachePath . DS . ltrim(preg_replace('~:~', '', $file), DS); if (!@file_exists($path)) { return false; } $timestamp = filemtime($path); if ($timestamp > filemtime($file) && $timestamp > $this->_watchedTimestamp) { return $path; } return false; }
[ "public", "function", "cached", "(", "$", "file", ")", "{", "if", "(", "!", "$", "cachePath", "=", "$", "this", "->", "cachePath", "(", ")", ")", "{", "return", "false", ";", "}", "$", "path", "=", "$", "cachePath", ".", "DS", ".", "ltrim", "(", ...
Gets a cached file path. @param string $file The source file path. @return string|boolean The cached file path or `false` if the cached file is not valid or is not cached.
[ "Gets", "a", "cached", "file", "path", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L306-L322
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.findPath
public function findPath($namespace, $forceDir = false) { $paths = static::prefixes(); $logicalPath = trim(strtr($namespace, '\\', DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); foreach ($paths as $prefix => $dirs) { if (strpos($namespace, $prefix) !== 0) { continue; } foreach ($dirs as $dir) { $root = $dir . DIRECTORY_SEPARATOR . substr($logicalPath, strlen($prefix)); if ($path = $this->_path($root, $forceDir)) { return realpath($path); } } } }
php
public function findPath($namespace, $forceDir = false) { $paths = static::prefixes(); $logicalPath = trim(strtr($namespace, '\\', DIRECTORY_SEPARATOR), DIRECTORY_SEPARATOR); foreach ($paths as $prefix => $dirs) { if (strpos($namespace, $prefix) !== 0) { continue; } foreach ($dirs as $dir) { $root = $dir . DIRECTORY_SEPARATOR . substr($logicalPath, strlen($prefix)); if ($path = $this->_path($root, $forceDir)) { return realpath($path); } } } }
[ "public", "function", "findPath", "(", "$", "namespace", ",", "$", "forceDir", "=", "false", ")", "{", "$", "paths", "=", "static", "::", "prefixes", "(", ")", ";", "$", "logicalPath", "=", "trim", "(", "strtr", "(", "$", "namespace", ",", "'\\\\'", ...
Returns the path of a namespace or fully namespaced class name. @param string $namespace A namespace. @param boolean $forceDir Only consider directories paths. @return string|null Returns the found path or `null` if not path is found.
[ "Returns", "the", "path", "of", "a", "namespace", "or", "fully", "namespaced", "class", "name", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L394-L411
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader._path
protected function _path($path, $forceDir) { if ($forceDir) { return is_dir($path) ? $path : null; } if (file_exists($file = $path . '.php')) { return $file ; } if (file_exists($file = $path . '.hh')) { return $file; } if (is_dir($path)) { return $path; } }
php
protected function _path($path, $forceDir) { if ($forceDir) { return is_dir($path) ? $path : null; } if (file_exists($file = $path . '.php')) { return $file ; } if (file_exists($file = $path . '.hh')) { return $file; } if (is_dir($path)) { return $path; } }
[ "protected", "function", "_path", "(", "$", "path", ",", "$", "forceDir", ")", "{", "if", "(", "$", "forceDir", ")", "{", "return", "is_dir", "(", "$", "path", ")", "?", "$", "path", ":", "null", ";", "}", "if", "(", "file_exists", "(", "$", "fil...
Build full path according to a root path. @param string $path A root path. @param boolean $forceDir Only consider directories paths. @return string|null Returns the found path or `null` if not path is found.
[ "Build", "full", "path", "according", "to", "a", "root", "path", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L420-L434
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.add
public function add($prefix, $paths, $prepend = false) { if (!$prefix) { if ($prepend) { $this->_fallbackDirsPsr0 = array_merge( (array) $paths, $this->_fallbackDirsPsr0 ); } else { $this->_fallbackDirsPsr0 = array_merge( $this->_fallbackDirsPsr0, (array) $paths ); } return; } $first = $prefix[0]; if (!isset($this->_prefixesPsr0[$first][$prefix])) { $this->_prefixesPsr0[$first][$prefix] = (array) $paths; return; } if ($prepend) { $this->_prefixesPsr0[$first][$prefix] = array_merge( (array) $paths, $this->_prefixesPsr0[$first][$prefix] ); } else { $this->_prefixesPsr0[$first][$prefix] = array_merge( $this->_prefixesPsr0[$first][$prefix], (array) $paths ); } }
php
public function add($prefix, $paths, $prepend = false) { if (!$prefix) { if ($prepend) { $this->_fallbackDirsPsr0 = array_merge( (array) $paths, $this->_fallbackDirsPsr0 ); } else { $this->_fallbackDirsPsr0 = array_merge( $this->_fallbackDirsPsr0, (array) $paths ); } return; } $first = $prefix[0]; if (!isset($this->_prefixesPsr0[$first][$prefix])) { $this->_prefixesPsr0[$first][$prefix] = (array) $paths; return; } if ($prepend) { $this->_prefixesPsr0[$first][$prefix] = array_merge( (array) $paths, $this->_prefixesPsr0[$first][$prefix] ); } else { $this->_prefixesPsr0[$first][$prefix] = array_merge( $this->_prefixesPsr0[$first][$prefix], (array) $paths ); } }
[ "public", "function", "add", "(", "$", "prefix", ",", "$", "paths", ",", "$", "prepend", "=", "false", ")", "{", "if", "(", "!", "$", "prefix", ")", "{", "if", "(", "$", "prepend", ")", "{", "$", "this", "->", "_fallbackDirsPsr0", "=", "array_merge...
Registers a set of PSR-0 directories for a given prefix, either appending or prepending to the ones previously set for this prefix. @param string $prefix The prefix @param array|string $paths The PSR-0 root directories @param bool $prepend Whether to prepend the directories
[ "Registers", "a", "set", "of", "PSR", "-", "0", "directories", "for", "a", "given", "prefix", "either", "appending", "or", "prepending", "to", "the", "ones", "previously", "set", "for", "this", "prefix", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L539-L574
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.addPsr4
public function addPsr4($prefix, $paths, $prepend = false) { if (!$prefix) { // Register directories for the root namespace. if ($prepend) { $this->_fallbackDirsPsr4 = array_merge( (array) $paths, $this->_fallbackDirsPsr4 ); } else { $this->_fallbackDirsPsr4 = array_merge( $this->_fallbackDirsPsr4, (array) $paths ); } } elseif (!isset($this->_prefixDirsPsr4[$prefix])) { // Register directories for a new namespace. $length = strlen($prefix); if ('\\' !== $prefix[$length - 1]) { throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->_prefixLengthsPsr4[$prefix[0]][$prefix] = $length; $this->_prefixDirsPsr4[$prefix] = (array) $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. $this->_prefixDirsPsr4[$prefix] = array_merge( (array) $paths, $this->_prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. $this->_prefixDirsPsr4[$prefix] = array_merge( $this->_prefixDirsPsr4[$prefix], (array) $paths ); } }
php
public function addPsr4($prefix, $paths, $prepend = false) { if (!$prefix) { // Register directories for the root namespace. if ($prepend) { $this->_fallbackDirsPsr4 = array_merge( (array) $paths, $this->_fallbackDirsPsr4 ); } else { $this->_fallbackDirsPsr4 = array_merge( $this->_fallbackDirsPsr4, (array) $paths ); } } elseif (!isset($this->_prefixDirsPsr4[$prefix])) { // Register directories for a new namespace. $length = strlen($prefix); if ('\\' !== $prefix[$length - 1]) { throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->_prefixLengthsPsr4[$prefix[0]][$prefix] = $length; $this->_prefixDirsPsr4[$prefix] = (array) $paths; } elseif ($prepend) { // Prepend directories for an already registered namespace. $this->_prefixDirsPsr4[$prefix] = array_merge( (array) $paths, $this->_prefixDirsPsr4[$prefix] ); } else { // Append directories for an already registered namespace. $this->_prefixDirsPsr4[$prefix] = array_merge( $this->_prefixDirsPsr4[$prefix], (array) $paths ); } }
[ "public", "function", "addPsr4", "(", "$", "prefix", ",", "$", "paths", ",", "$", "prepend", "=", "false", ")", "{", "if", "(", "!", "$", "prefix", ")", "{", "// Register directories for the root namespace.", "if", "(", "$", "prepend", ")", "{", "$", "th...
Registers a set of PSR-4 directories for a given namespace, either appending or prepending to the ones previously set for this namespace. @param string $prefix The prefix/namespace, with trailing '\\' @param array|string $paths The PSR-4 base directories @param bool $prepend Whether to prepend the directories @throws \InvalidArgumentException
[ "Registers", "a", "set", "of", "PSR", "-", "4", "directories", "for", "a", "given", "namespace", "either", "appending", "or", "prepending", "to", "the", "ones", "previously", "set", "for", "this", "namespace", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L586-L622
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.set
public function set($prefix, $paths) { if (!$prefix) { $this->_fallbackDirsPsr0 = (array) $paths; } else { $this->_prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; } }
php
public function set($prefix, $paths) { if (!$prefix) { $this->_fallbackDirsPsr0 = (array) $paths; } else { $this->_prefixesPsr0[$prefix[0]][$prefix] = (array) $paths; } }
[ "public", "function", "set", "(", "$", "prefix", ",", "$", "paths", ")", "{", "if", "(", "!", "$", "prefix", ")", "{", "$", "this", "->", "_fallbackDirsPsr0", "=", "(", "array", ")", "$", "paths", ";", "}", "else", "{", "$", "this", "->", "_prefi...
Registers a set of PSR-0 directories for a given prefix, replacing any others previously set for this prefix. @param string $prefix The prefix @param array|string $paths The PSR-0 base directories
[ "Registers", "a", "set", "of", "PSR", "-", "0", "directories", "for", "a", "given", "prefix", "replacing", "any", "others", "previously", "set", "for", "this", "prefix", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L631-L638
train
kahlan/kahlan
src/Jit/ClassLoader.php
ClassLoader.setPsr4
public function setPsr4($prefix, $paths) { if (!$prefix) { $this->_fallbackDirsPsr4 = (array) $paths; } else { $length = strlen($prefix); if ('\\' !== $prefix[$length - 1]) { throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->_prefixLengthsPsr4[$prefix[0]][$prefix] = $length; $this->_prefixDirsPsr4[$prefix] = (array) $paths; } }
php
public function setPsr4($prefix, $paths) { if (!$prefix) { $this->_fallbackDirsPsr4 = (array) $paths; } else { $length = strlen($prefix); if ('\\' !== $prefix[$length - 1]) { throw new \InvalidArgumentException("A non-empty PSR-4 prefix must end with a namespace separator."); } $this->_prefixLengthsPsr4[$prefix[0]][$prefix] = $length; $this->_prefixDirsPsr4[$prefix] = (array) $paths; } }
[ "public", "function", "setPsr4", "(", "$", "prefix", ",", "$", "paths", ")", "{", "if", "(", "!", "$", "prefix", ")", "{", "$", "this", "->", "_fallbackDirsPsr4", "=", "(", "array", ")", "$", "paths", ";", "}", "else", "{", "$", "length", "=", "s...
Registers a set of PSR-4 directories for a given namespace, replacing any others previously set for this namespace. @param string $prefix The prefix/namespace, with trailing '\\' @param array|string $paths The PSR-4 base directories @throws \InvalidArgumentException
[ "Registers", "a", "set", "of", "PSR", "-", "4", "directories", "for", "a", "given", "namespace", "replacing", "any", "others", "previously", "set", "for", "this", "namespace", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Jit/ClassLoader.php#L649-L661
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal._report
protected function _report($log) { $type = $log->type(); $this->_reportSuiteMessages($log); $this->_reportSpecMessage($log); $this->_reportFailure($log); $this->_indent = 0; }
php
protected function _report($log) { $type = $log->type(); $this->_reportSuiteMessages($log); $this->_reportSpecMessage($log); $this->_reportFailure($log); $this->_indent = 0; }
[ "protected", "function", "_report", "(", "$", "log", ")", "{", "$", "type", "=", "$", "log", "->", "type", "(", ")", ";", "$", "this", "->", "_reportSuiteMessages", "(", "$", "log", ")", ";", "$", "this", "->", "_reportSpecMessage", "(", "$", "log", ...
Print a spec report with its parents messages. @param object $log A spec log instance.
[ "Print", "a", "spec", "report", "with", "its", "parents", "messages", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L196-L203
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal._reportSuiteMessages
protected function _reportSuiteMessages($log) { $this->_indent = 0; $messages = array_values(array_filter($log->messages())); array_pop($messages); foreach ($messages as $message) { $this->write($message); $this->write("\n"); $this->_indent++; } }
php
protected function _reportSuiteMessages($log) { $this->_indent = 0; $messages = array_values(array_filter($log->messages())); array_pop($messages); foreach ($messages as $message) { $this->write($message); $this->write("\n"); $this->_indent++; } }
[ "protected", "function", "_reportSuiteMessages", "(", "$", "log", ")", "{", "$", "this", "->", "_indent", "=", "0", ";", "$", "messages", "=", "array_values", "(", "array_filter", "(", "$", "log", "->", "messages", "(", ")", ")", ")", ";", "array_pop", ...
Print an array of description messages to STDOUT @param \Kahlan\Log $log The Log instance
[ "Print", "an", "array", "of", "description", "messages", "to", "STDOUT" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L221-L231
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal._reportSpecMessage
protected function _reportSpecMessage($log) { $messages = $log->messages(); $message = end($messages); switch ($log->type()) { case 'passed': $this->write($this->_symbols['ok'], 'light-green'); $this->write(' '); $this->write("{$message}\n", 'dark-grey'); break; case 'skipped': $this->write($this->_symbols['ok'], 'light-grey'); $this->write(' '); $this->write("{$message}\n", 'light-grey'); break; case 'pending': $this->write($this->_symbols['ok'], 'cyan'); $this->write(' '); $this->write("{$message}\n", 'cyan'); break; case 'excluded': $this->write($this->_symbols['ok'], 'yellow'); $this->write(' '); $this->write("{$message}\n", 'yellow'); break; case 'failed': $this->write($this->_symbols['err'], 'red'); $this->write(' '); $this->write("{$message}\n", 'red'); break; case 'errored': $this->write($this->_symbols['err'], 'red'); $this->write(' '); $this->write("{$message}\n", 'red'); break; } }
php
protected function _reportSpecMessage($log) { $messages = $log->messages(); $message = end($messages); switch ($log->type()) { case 'passed': $this->write($this->_symbols['ok'], 'light-green'); $this->write(' '); $this->write("{$message}\n", 'dark-grey'); break; case 'skipped': $this->write($this->_symbols['ok'], 'light-grey'); $this->write(' '); $this->write("{$message}\n", 'light-grey'); break; case 'pending': $this->write($this->_symbols['ok'], 'cyan'); $this->write(' '); $this->write("{$message}\n", 'cyan'); break; case 'excluded': $this->write($this->_symbols['ok'], 'yellow'); $this->write(' '); $this->write("{$message}\n", 'yellow'); break; case 'failed': $this->write($this->_symbols['err'], 'red'); $this->write(' '); $this->write("{$message}\n", 'red'); break; case 'errored': $this->write($this->_symbols['err'], 'red'); $this->write(' '); $this->write("{$message}\n", 'red'); break; } }
[ "protected", "function", "_reportSpecMessage", "(", "$", "log", ")", "{", "$", "messages", "=", "$", "log", "->", "messages", "(", ")", ";", "$", "message", "=", "end", "(", "$", "messages", ")", ";", "switch", "(", "$", "log", "->", "type", "(", "...
Print a spec message report. @param object $log A spec log instance.
[ "Print", "a", "spec", "message", "report", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L238-L275
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal._reportFailure
protected function _reportFailure($log) { $this->_indent++; $type = $log->type(); switch ($type) { case "failed": foreach ($log->children() as $expectation) { if ($expectation->type() !== 'failed') { continue; } $data = $expectation->data(); $isExternal = isset($data['external']) && $data['external']; if ($isExternal) { $this->write("expectation failed in ", 'red'); } else { $this->write("expect->{$expectation->matcherName()}() failed in ", 'red'); } $this->write("`{$expectation->file()}` "); $this->write("line {$expectation->line()}", 'red'); $this->write("\n\n"); if ($isExternal) { $this->write($data['description']); $this->write("\n\n"); } else { $this->_reportDiff($expectation); } } break; case "errored": $backtrace = Debugger::backtrace(['trace' => $log->exception()]); $trace = reset($backtrace); $file = $trace['file']; $line = $trace['line']; $this->write("an uncaught exception has been thrown in ", 'magenta'); $this->write("`{$file}` "); $this->write("line {$line}", 'magenta'); $this->write("\n\n"); $this->write('message:', 'yellow'); $this->_reportException($log->exception()); $this->prefix($this->format(' ', 'n;;magenta') . ' '); $this->write(Debugger::trace(['trace' => $backtrace])); $this->prefix(''); $this->write("\n\n"); break; } $this->_indent--; }
php
protected function _reportFailure($log) { $this->_indent++; $type = $log->type(); switch ($type) { case "failed": foreach ($log->children() as $expectation) { if ($expectation->type() !== 'failed') { continue; } $data = $expectation->data(); $isExternal = isset($data['external']) && $data['external']; if ($isExternal) { $this->write("expectation failed in ", 'red'); } else { $this->write("expect->{$expectation->matcherName()}() failed in ", 'red'); } $this->write("`{$expectation->file()}` "); $this->write("line {$expectation->line()}", 'red'); $this->write("\n\n"); if ($isExternal) { $this->write($data['description']); $this->write("\n\n"); } else { $this->_reportDiff($expectation); } } break; case "errored": $backtrace = Debugger::backtrace(['trace' => $log->exception()]); $trace = reset($backtrace); $file = $trace['file']; $line = $trace['line']; $this->write("an uncaught exception has been thrown in ", 'magenta'); $this->write("`{$file}` "); $this->write("line {$line}", 'magenta'); $this->write("\n\n"); $this->write('message:', 'yellow'); $this->_reportException($log->exception()); $this->prefix($this->format(' ', 'n;;magenta') . ' '); $this->write(Debugger::trace(['trace' => $backtrace])); $this->prefix(''); $this->write("\n\n"); break; } $this->_indent--; }
[ "protected", "function", "_reportFailure", "(", "$", "log", ")", "{", "$", "this", "->", "_indent", "++", ";", "$", "type", "=", "$", "log", "->", "type", "(", ")", ";", "switch", "(", "$", "type", ")", "{", "case", "\"failed\"", ":", "foreach", "(...
Print an expectation report. @param object $log An specification log.
[ "Print", "an", "expectation", "report", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L282-L334
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal._reportDiff
protected function _reportDiff($log) { $data = $log->data(); $this->write("It expect actual "); if ($log->not()) { $this->write('NOT ', 'cyan'); $not = 'not '; } else { $not = ''; } $this->write("to {$log->description()}\n\n"); foreach ($data as $key => $value) { if (preg_match('~actual~', $key)) { $this->write("{$key}:\n", 'yellow'); $this->prefix($this->format(' ', 'n;;91') . ' '); } elseif (preg_match('~expected~', $key)) { $this->write("{$not}{$key}:\n", 'yellow'); $this->prefix($this->format(' ', 'n;;92') . ' '); } else { $this->write("{$key}:\n", 'yellow'); } $type = gettype($value); $toString = function ($instance) { return 'an instance of `' . get_class($instance) . '`'; }; $this->write("({$type}) " . Text::toString($value, ['object' => ['method' => $toString]])); $this->prefix(''); $this->write("\n"); } $this->write("\n"); }
php
protected function _reportDiff($log) { $data = $log->data(); $this->write("It expect actual "); if ($log->not()) { $this->write('NOT ', 'cyan'); $not = 'not '; } else { $not = ''; } $this->write("to {$log->description()}\n\n"); foreach ($data as $key => $value) { if (preg_match('~actual~', $key)) { $this->write("{$key}:\n", 'yellow'); $this->prefix($this->format(' ', 'n;;91') . ' '); } elseif (preg_match('~expected~', $key)) { $this->write("{$not}{$key}:\n", 'yellow'); $this->prefix($this->format(' ', 'n;;92') . ' '); } else { $this->write("{$key}:\n", 'yellow'); } $type = gettype($value); $toString = function ($instance) { return 'an instance of `' . get_class($instance) . '`'; }; $this->write("({$type}) " . Text::toString($value, ['object' => ['method' => $toString]])); $this->prefix(''); $this->write("\n"); } $this->write("\n"); }
[ "protected", "function", "_reportDiff", "(", "$", "log", ")", "{", "$", "data", "=", "$", "log", "->", "data", "(", ")", ";", "$", "this", "->", "write", "(", "\"It expect actual \"", ")", ";", "if", "(", "$", "log", "->", "not", "(", ")", ")", "...
Print diff of spec's data. @param array $log A log array.
[ "Print", "diff", "of", "spec", "s", "data", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L341-L374
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal._reportException
protected function _reportException($exception) { $msg = '`' . get_class($exception) .'` Code(' . $exception->getCode() . ') with '; $message = $exception->getMessage(); if ($message) { $msg .= 'message '. Text::dump($exception->getMessage()); } else { $msg .= 'no message'; } $this->write("{$msg}\n\n"); }
php
protected function _reportException($exception) { $msg = '`' . get_class($exception) .'` Code(' . $exception->getCode() . ') with '; $message = $exception->getMessage(); if ($message) { $msg .= 'message '. Text::dump($exception->getMessage()); } else { $msg .= 'no message'; } $this->write("{$msg}\n\n"); }
[ "protected", "function", "_reportException", "(", "$", "exception", ")", "{", "$", "msg", "=", "'`'", ".", "get_class", "(", "$", "exception", ")", ".", "'` Code('", ".", "$", "exception", "->", "getCode", "(", ")", ".", "') with '", ";", "$", "message",...
Print an exception to the outpout. @param object $exception An exception.
[ "Print", "an", "exception", "to", "the", "outpout", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L381-L391
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal.write
public function write($string, $options = null) { $indent = str_repeat($this->_indentValue, $this->indent()) . $this->prefix(); if ($newLine = ($string && $string[strlen($string) - 1] === "\n")) { $string = substr($string, 0, -1); } $string = str_replace("\n", "\n" . $indent, $string) . ($newLine ? "\n" : ''); $indent = $this->_newLine ? $indent : ''; $this->_newLine = $newLine; fwrite($this->_output, $indent . $this->format($string, $options)); }
php
public function write($string, $options = null) { $indent = str_repeat($this->_indentValue, $this->indent()) . $this->prefix(); if ($newLine = ($string && $string[strlen($string) - 1] === "\n")) { $string = substr($string, 0, -1); } $string = str_replace("\n", "\n" . $indent, $string) . ($newLine ? "\n" : ''); $indent = $this->_newLine ? $indent : ''; $this->_newLine = $newLine; fwrite($this->_output, $indent . $this->format($string, $options)); }
[ "public", "function", "write", "(", "$", "string", ",", "$", "options", "=", "null", ")", "{", "$", "indent", "=", "str_repeat", "(", "$", "this", "->", "_indentValue", ",", "$", "this", "->", "indent", "(", ")", ")", ".", "$", "this", "->", "prefi...
Print a string to output. @param string $string The string to print. @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'`
[ "Print", "a", "string", "to", "output", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L408-L422
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal.format
public function format($string, $options = null) { return $this->_colors ? Cli::color($string, $options) : $string; }
php
public function format($string, $options = null) { return $this->_colors ? Cli::color($string, $options) : $string; }
[ "public", "function", "format", "(", "$", "string", ",", "$", "options", "=", "null", ")", "{", "return", "$", "this", "->", "_colors", "?", "Cli", "::", "color", "(", "$", "string", ",", "$", "options", ")", ":", "$", "string", ";", "}" ]
Format a string to output. @param string $string The string to format. @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'`
[ "Format", "a", "string", "to", "output", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L467-L470
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal.readableSize
public function readableSize($value, $precision = 0, $base = 1024) { $i = 0; if ($value < 1) { return '0'; } $units = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; while (($value / $base) >= 1) { $value = $value / $base; $i++; } $unit = isset($units[$i]) ? $units[$i] : '?'; return round($value, $precision) . $unit; }
php
public function readableSize($value, $precision = 0, $base = 1024) { $i = 0; if ($value < 1) { return '0'; } $units = ['', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']; while (($value / $base) >= 1) { $value = $value / $base; $i++; } $unit = isset($units[$i]) ? $units[$i] : '?'; return round($value, $precision) . $unit; }
[ "public", "function", "readableSize", "(", "$", "value", ",", "$", "precision", "=", "0", ",", "$", "base", "=", "1024", ")", "{", "$", "i", "=", "0", ";", "if", "(", "$", "value", "<", "1", ")", "{", "return", "'0'", ";", "}", "$", "units", ...
Humanizes values using an appropriate unit. @param integer $value The value. @param integer $precision The required precision. @param integer $base The unit base. @return string The Humanized string value.
[ "Humanizes", "values", "using", "an", "appropriate", "unit", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L480-L494
train
kahlan/kahlan
src/Reporter/Terminal.php
Terminal._reportSummary
public function _reportSummary($summary) { $passed = $summary->passed(); $skipped = $summary->skipped(); $pending = $summary->pending(); $excluded = $summary->excluded(); $failed = $summary->failed(); $errored = $summary->errored(); $expectation = $summary->expectation(); $total = $summary->executable(); $this->write("Expectations : "); $this->write("{$expectation} Executed"); $this->write("\n"); $this->write("Specifications : "); $this->write("{$pending} Pending", 'cyan'); $this->write(", "); $this->write("{$excluded} Excluded", 'yellow'); $this->write(", "); $this->write("{$skipped} Skipped", 'light-grey'); $this->write("\n\n"); $this->write('Passed ' . ($passed), 'green'); $this->write(" of {$total} "); if ($failed + $errored) { $this->write('FAIL ', 'red'); $this->write('('); $comma = false; if ($failed) { $this->write('FAILURE: ' . $failed, 'red'); $comma = true; } if ($errored) { if ($comma) { $this->write(', '); } $this->write('EXCEPTION: ' . $errored, 'magenta'); } $this->write(')'); } else { $this->write('PASS', 'green'); } $time = number_format(microtime(true) - $this->_start, 3); $memory = $this->readableSize($summary->memoryUsage()); $this->write(" in {$time} seconds (using {$memory}B)"); $this->write("\n\n"); $this->_reportFocused($summary); }
php
public function _reportSummary($summary) { $passed = $summary->passed(); $skipped = $summary->skipped(); $pending = $summary->pending(); $excluded = $summary->excluded(); $failed = $summary->failed(); $errored = $summary->errored(); $expectation = $summary->expectation(); $total = $summary->executable(); $this->write("Expectations : "); $this->write("{$expectation} Executed"); $this->write("\n"); $this->write("Specifications : "); $this->write("{$pending} Pending", 'cyan'); $this->write(", "); $this->write("{$excluded} Excluded", 'yellow'); $this->write(", "); $this->write("{$skipped} Skipped", 'light-grey'); $this->write("\n\n"); $this->write('Passed ' . ($passed), 'green'); $this->write(" of {$total} "); if ($failed + $errored) { $this->write('FAIL ', 'red'); $this->write('('); $comma = false; if ($failed) { $this->write('FAILURE: ' . $failed, 'red'); $comma = true; } if ($errored) { if ($comma) { $this->write(', '); } $this->write('EXCEPTION: ' . $errored, 'magenta'); } $this->write(')'); } else { $this->write('PASS', 'green'); } $time = number_format(microtime(true) - $this->_start, 3); $memory = $this->readableSize($summary->memoryUsage()); $this->write(" in {$time} seconds (using {$memory}B)"); $this->write("\n\n"); $this->_reportFocused($summary); }
[ "public", "function", "_reportSummary", "(", "$", "summary", ")", "{", "$", "passed", "=", "$", "summary", "->", "passed", "(", ")", ";", "$", "skipped", "=", "$", "summary", "->", "skipped", "(", ")", ";", "$", "pending", "=", "$", "summary", "->", ...
Print a summary of specs execution to STDOUT @param object $summary The execution summary instance.
[ "Print", "a", "summary", "of", "specs", "execution", "to", "STDOUT" ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Terminal.php#L501-L549
train
kahlan/kahlan
src/Plugin/Pointcut.php
Pointcut.before
public static function before($method, $self, &$args) { if (!Suite::registered()) { return false; } list($class, $name) = explode('::', $method); $lsb = is_object($self) ? get_class($self) : $self; if (!Suite::registered($lsb) && !Suite::registered($class)) { return false; } if ($name === '__call' || $name === '__callStatic') { $name = array_shift($args); $args = array_shift($args); } return static::_stubbedMethod($lsb, $self, $class, $name, $args); }
php
public static function before($method, $self, &$args) { if (!Suite::registered()) { return false; } list($class, $name) = explode('::', $method); $lsb = is_object($self) ? get_class($self) : $self; if (!Suite::registered($lsb) && !Suite::registered($class)) { return false; } if ($name === '__call' || $name === '__callStatic') { $name = array_shift($args); $args = array_shift($args); } return static::_stubbedMethod($lsb, $self, $class, $name, $args); }
[ "public", "static", "function", "before", "(", "$", "method", ",", "$", "self", ",", "&", "$", "args", ")", "{", "if", "(", "!", "Suite", "::", "registered", "(", ")", ")", "{", "return", "false", ";", "}", "list", "(", "$", "class", ",", "$", ...
Point cut called before method execution. @param string $method The method name @param Pointcut $self The Pointcut instance @param array $args The arguments @return bool If `true` is returned, the normal execution of the method is aborted.
[ "Point", "cut", "called", "before", "method", "execution", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Pointcut.php#L27-L47
train
kahlan/kahlan
src/Plugin/Pointcut.php
Pointcut._stubbedMethod
protected static function _stubbedMethod($lsb, $self, $class, $name, $args) { if (is_object($self)) { $list = $lsb === $class ? [$self, $lsb] : [$self, $lsb, $class]; } else { $list = $lsb === $class ? [$lsb] : [$lsb, $class]; $name = '::' . $name; } $stub = static::$_classes['stub']; $method = $stub::find($list, $name, $args); Calls::log($list, compact('name', 'args', 'method')); return $method ?: false; }
php
protected static function _stubbedMethod($lsb, $self, $class, $name, $args) { if (is_object($self)) { $list = $lsb === $class ? [$self, $lsb] : [$self, $lsb, $class]; } else { $list = $lsb === $class ? [$lsb] : [$lsb, $class]; $name = '::' . $name; } $stub = static::$_classes['stub']; $method = $stub::find($list, $name, $args); Calls::log($list, compact('name', 'args', 'method')); return $method ?: false; }
[ "protected", "static", "function", "_stubbedMethod", "(", "$", "lsb", ",", "$", "self", ",", "$", "class", ",", "$", "name", ",", "$", "args", ")", "{", "if", "(", "is_object", "(", "$", "self", ")", ")", "{", "$", "list", "=", "$", "lsb", "===",...
Checks if the called method has been stubbed. @param string $lsb Late state binding class name. @param object|string $self The object instance or a fully-namespaces class name. @param string $class The class name. @param string $name The method name. @param string $args The passed arguments. @return boolean Returns `true` if the method has been stubbed.
[ "Checks", "if", "the", "called", "method", "has", "been", "stubbed", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Pointcut.php#L59-L74
train
kahlan/kahlan
src/Log.php
Log.exception
public function exception($exception = null) { if (!func_num_args()) { return $this->_exception; } $this->_exception = $exception; return $this; }
php
public function exception($exception = null) { if (!func_num_args()) { return $this->_exception; } $this->_exception = $exception; return $this; }
[ "public", "function", "exception", "(", "$", "exception", "=", "null", ")", "{", "if", "(", "!", "func_num_args", "(", ")", ")", "{", "return", "$", "this", "->", "_exception", ";", "}", "$", "this", "->", "_exception", "=", "$", "exception", ";", "r...
Gets the exception related to the report. @return object
[ "Gets", "the", "exception", "related", "to", "the", "report", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Log.php#L218-L225
train
kahlan/kahlan
src/Log.php
Log.backtrace
public function backtrace($backtrace = []) { if (!func_num_args()) { return $this->_backtrace; } if ($this->_backtrace = $backtrace) { foreach ($this->_backtrace as $trace) { if (isset($trace['file'])) { $this->_file = preg_replace('~' . preg_quote(getcwd(), '~') . '~', '', '.' . $trace['file']); $this->_line = $trace['line']; break; } } } return $this; }
php
public function backtrace($backtrace = []) { if (!func_num_args()) { return $this->_backtrace; } if ($this->_backtrace = $backtrace) { foreach ($this->_backtrace as $trace) { if (isset($trace['file'])) { $this->_file = preg_replace('~' . preg_quote(getcwd(), '~') . '~', '', '.' . $trace['file']); $this->_line = $trace['line']; break; } } } return $this; }
[ "public", "function", "backtrace", "(", "$", "backtrace", "=", "[", "]", ")", "{", "if", "(", "!", "func_num_args", "(", ")", ")", "{", "return", "$", "this", "->", "_backtrace", ";", "}", "if", "(", "$", "this", "->", "_backtrace", "=", "$", "back...
Gets the backtrace related to the report. @return array
[ "Gets", "the", "backtrace", "related", "to", "the", "report", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Log.php#L232-L247
train
kahlan/kahlan
src/Log.php
Log.add
public function add($type, $data = []) { if ($this->type() === 'passed' && $type === 'failed') { $this->type('failed'); } $data['type'] = $type; if (!isset($data['backtrace'])) { $data['backtrace'] = []; } else { $data['backtrace'] = Debugger::focus($this->block()->suite()->backtraceFocus(), $data['backtrace'], 1); } $child = new static($data + ['block' => $this->_block]); $this->_children[] = $child; return $child; }
php
public function add($type, $data = []) { if ($this->type() === 'passed' && $type === 'failed') { $this->type('failed'); } $data['type'] = $type; if (!isset($data['backtrace'])) { $data['backtrace'] = []; } else { $data['backtrace'] = Debugger::focus($this->block()->suite()->backtraceFocus(), $data['backtrace'], 1); } $child = new static($data + ['block' => $this->_block]); $this->_children[] = $child; return $child; }
[ "public", "function", "add", "(", "$", "type", ",", "$", "data", "=", "[", "]", ")", "{", "if", "(", "$", "this", "->", "type", "(", ")", "===", "'passed'", "&&", "$", "type", "===", "'failed'", ")", "{", "$", "this", "->", "type", "(", "'faile...
Adds an expectation report and emits a report event. @param array $data The report data.
[ "Adds", "an", "expectation", "report", "and", "emits", "a", "report", "event", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Log.php#L294-L308
train
kahlan/kahlan
src/Plugin/Monkey.php
Monkey.patch
public static function patch($source, $dest = null) { $source = ltrim($source, '\\'); if (is_object($source) || class_exists($source)) { $reference = $source; } else { $reference = null; if (MonkeyPatcher::blacklisted($source)) { throw new Exception("Monkey patching `{$source}()` is not supported by Kahlan."); } } $method = static::$_registered[$source] = new Method(compact('reference')); if (!$dest) { return $method; } $method->toBe($dest); return $method; }
php
public static function patch($source, $dest = null) { $source = ltrim($source, '\\'); if (is_object($source) || class_exists($source)) { $reference = $source; } else { $reference = null; if (MonkeyPatcher::blacklisted($source)) { throw new Exception("Monkey patching `{$source}()` is not supported by Kahlan."); } } $method = static::$_registered[$source] = new Method(compact('reference')); if (!$dest) { return $method; } $method->toBe($dest); return $method; }
[ "public", "static", "function", "patch", "(", "$", "source", ",", "$", "dest", "=", "null", ")", "{", "$", "source", "=", "ltrim", "(", "$", "source", ",", "'\\\\'", ")", ";", "if", "(", "is_object", "(", "$", "source", ")", "||", "class_exists", "...
Setup a monkey patch. @param string $source A fully namespaced reference string. @param string $dest A fully namespaced reference string.
[ "Setup", "a", "monkey", "patch", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Monkey.php#L25-L42
train
kahlan/kahlan
src/Plugin/Monkey.php
Monkey.patched
public static function patched($namespace, $className, $methodName, &$substitute = null) { $name = $className ?: $methodName; if ($namespace && ($className || function_exists("{$namespace}\\{$name}"))) { $name = "{$namespace}\\{$name}"; } $method = isset(static::$_registered[$name]) ? static::$_registered[$name] : null; if (!$methodName) { $fake = $method ? $method->substitute() : null; if (is_object($fake)) { $substitute = $fake; } return $fake ?: $name; } if (!$method) { if (!Suite::registered($name)) { return $name; } } elseif ($method->actsAsAReplacement()) { return $method->closure(); } return function () use ($name, $method) { $args = func_get_args(); if (Suite::registered($name)) { Calls::log(null, compact('name', 'args')); } if ($method && $method->matchArgs($args)) { return $method($args); } return call_user_func_array($name, $args); }; }
php
public static function patched($namespace, $className, $methodName, &$substitute = null) { $name = $className ?: $methodName; if ($namespace && ($className || function_exists("{$namespace}\\{$name}"))) { $name = "{$namespace}\\{$name}"; } $method = isset(static::$_registered[$name]) ? static::$_registered[$name] : null; if (!$methodName) { $fake = $method ? $method->substitute() : null; if (is_object($fake)) { $substitute = $fake; } return $fake ?: $name; } if (!$method) { if (!Suite::registered($name)) { return $name; } } elseif ($method->actsAsAReplacement()) { return $method->closure(); } return function () use ($name, $method) { $args = func_get_args(); if (Suite::registered($name)) { Calls::log(null, compact('name', 'args')); } if ($method && $method->matchArgs($args)) { return $method($args); } return call_user_func_array($name, $args); }; }
[ "public", "static", "function", "patched", "(", "$", "namespace", ",", "$", "className", ",", "$", "methodName", ",", "&", "$", "substitute", "=", "null", ")", "{", "$", "name", "=", "$", "className", "?", ":", "$", "methodName", ";", "if", "(", "$",...
Patches the string. @param string $namespace The namespace. @param string $className The fully namespaced class reference string. @param string $methodName The method/function name. @return string A fully namespaced reference.
[ "Patches", "the", "string", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Monkey.php#L52-L89
train
kahlan/kahlan
src/Expectation.php
Expectation._matcher
public function _matcher($matcherName, $actual) { if (!Matcher::exists($matcherName, true)) { throw new Exception("Unexisting matcher attached to `'{$matcherName}'`."); } $matcher = null; foreach (Matcher::get($matcherName, true) as $target => $value) { if (!$target) { $matcher = $value; continue; } if ($actual instanceof $target) { $matcher = $value; } } if (!$matcher) { throw new Exception("Unexisting matcher attached to `'{$matcherName}'` for `{$target}`."); } return $matcher; }
php
public function _matcher($matcherName, $actual) { if (!Matcher::exists($matcherName, true)) { throw new Exception("Unexisting matcher attached to `'{$matcherName}'`."); } $matcher = null; foreach (Matcher::get($matcherName, true) as $target => $value) { if (!$target) { $matcher = $value; continue; } if ($actual instanceof $target) { $matcher = $value; } } if (!$matcher) { throw new Exception("Unexisting matcher attached to `'{$matcherName}'` for `{$target}`."); } return $matcher; }
[ "public", "function", "_matcher", "(", "$", "matcherName", ",", "$", "actual", ")", "{", "if", "(", "!", "Matcher", "::", "exists", "(", "$", "matcherName", ",", "true", ")", ")", "{", "throw", "new", "Exception", "(", "\"Unexisting matcher attached to `'{$m...
Returns a compatible matcher class name according to a passed actual value. @param string $matcherName The name of the matcher. @param mixed $actual The actual value. @return string A matcher class name.
[ "Returns", "a", "compatible", "matcher", "class", "name", "according", "to", "a", "passed", "actual", "value", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Expectation.php#L247-L270
train
kahlan/kahlan
src/Expectation.php
Expectation._spin
protected function _spin($closure) { $timeout = $this->timeout(); if ($timeout <= 0) { $closure(); } else { Code::spin($closure, $timeout); } }
php
protected function _spin($closure) { $timeout = $this->timeout(); if ($timeout <= 0) { $closure(); } else { Code::spin($closure, $timeout); } }
[ "protected", "function", "_spin", "(", "$", "closure", ")", "{", "$", "timeout", "=", "$", "this", "->", "timeout", "(", ")", ";", "if", "(", "$", "timeout", "<=", "0", ")", "{", "$", "closure", "(", ")", ";", "}", "else", "{", "Code", "::", "s...
Runs the expectation. @param Closure $closure The closure to run/spin.
[ "Runs", "the", "expectation", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Expectation.php#L352-L360
train
kahlan/kahlan
src/Expectation.php
Expectation._resolve
protected function _resolve() { if (!$this->_deferred) { return; } $data = $this->_deferred; $instance = $data['instance']; $this->_not = $data['not']; $boolean = $instance->resolve(); $data['description'] = $instance->description(); $data['backtrace'] = $instance->backtrace(); $this->_log($boolean, $data); $this->_deferred = null; }
php
protected function _resolve() { if (!$this->_deferred) { return; } $data = $this->_deferred; $instance = $data['instance']; $this->_not = $data['not']; $boolean = $instance->resolve(); $data['description'] = $instance->description(); $data['backtrace'] = $instance->backtrace(); $this->_log($boolean, $data); $this->_deferred = null; }
[ "protected", "function", "_resolve", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_deferred", ")", "{", "return", ";", "}", "$", "data", "=", "$", "this", "->", "_deferred", ";", "$", "instance", "=", "$", "data", "[", "'instance'", "]", ";",...
Resolves deferred matchers.
[ "Resolves", "deferred", "matchers", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Expectation.php#L365-L380
train
kahlan/kahlan
src/Expectation.php
Expectation._log
protected function _log($boolean, $data = []) { $not = $this->_not; $pass = $not ? !$boolean : $boolean; if ($pass) { $data['type'] = 'passed'; } else { $data['type'] = 'failed'; $this->_passed = false; } $description = $data['description']; if (is_array($description)) { $data['data'] = $description['data']; $data['description'] = $description['description']; } $data += ['backtrace' => Debugger::backtrace()]; $data['not'] = $not; $this->_logs[] = $data; $this->_not = false; return $boolean; }
php
protected function _log($boolean, $data = []) { $not = $this->_not; $pass = $not ? !$boolean : $boolean; if ($pass) { $data['type'] = 'passed'; } else { $data['type'] = 'failed'; $this->_passed = false; } $description = $data['description']; if (is_array($description)) { $data['data'] = $description['data']; $data['description'] = $description['description']; } $data += ['backtrace' => Debugger::backtrace()]; $data['not'] = $not; $this->_logs[] = $data; $this->_not = false; return $boolean; }
[ "protected", "function", "_log", "(", "$", "boolean", ",", "$", "data", "=", "[", "]", ")", "{", "$", "not", "=", "$", "this", "->", "_not", ";", "$", "pass", "=", "$", "not", "?", "!", "$", "boolean", ":", "$", "boolean", ";", "if", "(", "$"...
Logs a result. @param boolean $boolean Set `true` for success and `false` for failure. @param array $data Test details array. @return boolean
[ "Logs", "a", "result", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Expectation.php#L389-L411
train
kahlan/kahlan
src/Expectation.php
Expectation.process
public function process() { if (!$this->_processed) { $this->_process(); $this->_resolve(); } $this->_processed = true; return $this->_passed !== false; }
php
public function process() { if (!$this->_processed) { $this->_process(); $this->_resolve(); } $this->_processed = true; return $this->_passed !== false; }
[ "public", "function", "process", "(", ")", "{", "if", "(", "!", "$", "this", "->", "_processed", ")", "{", "$", "this", "->", "_process", "(", ")", ";", "$", "this", "->", "_resolve", "(", ")", ";", "}", "$", "this", "->", "_processed", "=", "tru...
Run the expectation. @return boolean Returns `true` if passed, `false` otherwise.
[ "Run", "the", "expectation", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Expectation.php#L432-L440
train
kahlan/kahlan
src/Expectation.php
Expectation.clear
public function clear() { $this->_actual = null; $this->_passed = null; $this->_processed = null; $this->_not = false; $this->_timeout = 0; $this->_logs = []; $this->_deferred = null; }
php
public function clear() { $this->_actual = null; $this->_passed = null; $this->_processed = null; $this->_not = false; $this->_timeout = 0; $this->_logs = []; $this->_deferred = null; }
[ "public", "function", "clear", "(", ")", "{", "$", "this", "->", "_actual", "=", "null", ";", "$", "this", "->", "_passed", "=", "null", ";", "$", "this", "->", "_processed", "=", "null", ";", "$", "this", "->", "_not", "=", "false", ";", "$", "t...
Clears the instance.
[ "Clears", "the", "instance", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Expectation.php#L455-L464
train
kahlan/kahlan
src/Block/Specification.php
Specification.reset
public function reset() { $this->_passed = null; $this->_expectations = []; $this->_log = new Log([ 'block' => $this, 'backtrace' => $this->_backtrace ]); return $this; }
php
public function reset() { $this->_passed = null; $this->_expectations = []; $this->_log = new Log([ 'block' => $this, 'backtrace' => $this->_backtrace ]); return $this; }
[ "public", "function", "reset", "(", ")", "{", "$", "this", "->", "_passed", "=", "null", ";", "$", "this", "->", "_expectations", "=", "[", "]", ";", "$", "this", "->", "_log", "=", "new", "Log", "(", "[", "'block'", "=>", "$", "this", ",", "'bac...
Reset the specification. @return Expectation
[ "Reset", "the", "specification", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Specification.php#L48-L57
train
kahlan/kahlan
src/Block/Specification.php
Specification.waitsFor
public function waitsFor($actual, $timeout = 0) { $timeout = $timeout ?: $this->timeout(); $closure = $actual instanceof Closure ? $actual : function () use ($actual) { return $actual; }; $spec = new static(['closure' => $closure]); return $this->expect($spec, $timeout); }
php
public function waitsFor($actual, $timeout = 0) { $timeout = $timeout ?: $this->timeout(); $closure = $actual instanceof Closure ? $actual : function () use ($actual) { return $actual; }; $spec = new static(['closure' => $closure]); return $this->expect($spec, $timeout); }
[ "public", "function", "waitsFor", "(", "$", "actual", ",", "$", "timeout", "=", "0", ")", "{", "$", "timeout", "=", "$", "timeout", "?", ":", "$", "this", "->", "timeout", "(", ")", ";", "$", "closure", "=", "$", "actual", "instanceof", "Closure", ...
The waitsFor statement. @param mixed $actual The expression to check @return mixed
[ "The", "waitsFor", "statement", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Specification.php#L95-L104
train
kahlan/kahlan
src/Block/Specification.php
Specification._execute
protected function _execute() { $result = null; $spec = function () { $this->_expectations = []; $closure = $this->_closure; $result = $this->_suite->runBlock($this, $closure, 'specification'); foreach ($this->_expectations as $expectation) { $this->_passed = $expectation->process() && $this->_passed; } return $result; }; $suite = $this->suite(); return $spec(); }
php
protected function _execute() { $result = null; $spec = function () { $this->_expectations = []; $closure = $this->_closure; $result = $this->_suite->runBlock($this, $closure, 'specification'); foreach ($this->_expectations as $expectation) { $this->_passed = $expectation->process() && $this->_passed; } return $result; }; $suite = $this->suite(); return $spec(); }
[ "protected", "function", "_execute", "(", ")", "{", "$", "result", "=", "null", ";", "$", "spec", "=", "function", "(", ")", "{", "$", "this", "->", "_expectations", "=", "[", "]", ";", "$", "closure", "=", "$", "this", "->", "_closure", ";", "$", ...
Spec execution helper.
[ "Spec", "execution", "helper", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Specification.php#L109-L124
train
kahlan/kahlan
src/Block/Specification.php
Specification._blockEnd
protected function _blockEnd($runAfterEach = true) { $type = $this->log()->type(); foreach ($this->_expectations as $expectation) { if (!($logs = $expectation->logs()) && $type !== 'errored') { $this->log()->type('pending'); } foreach ($logs as $log) { $this->log($log['type'], $log); } } if ($type === 'passed' && empty($this->_expectations)) { $this->log()->type('pending'); } $type = $this->log()->type(); if ($type === 'failed' || $type === 'errored') { $this->_passed = false; $this->suite()->failure(); } if ($this->_parent && $runAfterEach) { try { $this->_parent->runCallbacks('afterEach'); } catch (Exception $exception) { $this->_exception($exception, true); } } $this->summary()->log($this->log()); $this->report('specEnd', $this->log()); Suite::current()->scope()->clear(); $this->suite()->autoclear(); }
php
protected function _blockEnd($runAfterEach = true) { $type = $this->log()->type(); foreach ($this->_expectations as $expectation) { if (!($logs = $expectation->logs()) && $type !== 'errored') { $this->log()->type('pending'); } foreach ($logs as $log) { $this->log($log['type'], $log); } } if ($type === 'passed' && empty($this->_expectations)) { $this->log()->type('pending'); } $type = $this->log()->type(); if ($type === 'failed' || $type === 'errored') { $this->_passed = false; $this->suite()->failure(); } if ($this->_parent && $runAfterEach) { try { $this->_parent->runCallbacks('afterEach'); } catch (Exception $exception) { $this->_exception($exception, true); } } $this->summary()->log($this->log()); $this->report('specEnd', $this->log()); Suite::current()->scope()->clear(); $this->suite()->autoclear(); }
[ "protected", "function", "_blockEnd", "(", "$", "runAfterEach", "=", "true", ")", "{", "$", "type", "=", "$", "this", "->", "log", "(", ")", "->", "type", "(", ")", ";", "foreach", "(", "$", "this", "->", "_expectations", "as", "$", "expectation", ")...
End spec execution helper.
[ "End", "spec", "execution", "helper", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Specification.php#L140-L176
train
kahlan/kahlan
src/Block/Specification.php
Specification.logs
public function logs() { $logs = []; foreach ($this->_expectations as $expectation) { foreach ($expectation->logs() as $log) { $logs[] = $log; } } return $logs; }
php
public function logs() { $logs = []; foreach ($this->_expectations as $expectation) { foreach ($expectation->logs() as $log) { $logs[] = $log; } } return $logs; }
[ "public", "function", "logs", "(", ")", "{", "$", "logs", "=", "[", "]", ";", "foreach", "(", "$", "this", "->", "_expectations", "as", "$", "expectation", ")", "{", "foreach", "(", "$", "expectation", "->", "logs", "(", ")", "as", "$", "log", ")",...
Returns execution log. @return array
[ "Returns", "execution", "log", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Block/Specification.php#L183-L192
train
kahlan/kahlan
src/Reporter/Coverage/Collector.php
Collector.start
public function start() { if ($collector = end(static::$_collectors)) { $collector->add($collector->_driver->stop()); } static::$_collectors[] = $this; $this->_driver->start(); return true; }
php
public function start() { if ($collector = end(static::$_collectors)) { $collector->add($collector->_driver->stop()); } static::$_collectors[] = $this; $this->_driver->start(); return true; }
[ "public", "function", "start", "(", ")", "{", "if", "(", "$", "collector", "=", "end", "(", "static", "::", "$", "_collectors", ")", ")", "{", "$", "collector", "->", "add", "(", "$", "collector", "->", "_driver", "->", "stop", "(", ")", ")", ";", ...
Starts collecting coverage data. @return boolean
[ "Starts", "collecting", "coverage", "data", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Collector.php#L164-L172
train
kahlan/kahlan
src/Reporter/Coverage/Collector.php
Collector.stop
public function stop($mergeToParent = true) { $collector = end(static::$_collectors); if ($collector !== $this) { return false; } array_pop(static::$_collectors); $collected = $this->_driver->stop(); $this->add($collected); $collector = end(static::$_collectors); if (!$collector) { return true; } $collector->add($mergeToParent ? $collected : []); $collector->_driver->start(); return true; }
php
public function stop($mergeToParent = true) { $collector = end(static::$_collectors); if ($collector !== $this) { return false; } array_pop(static::$_collectors); $collected = $this->_driver->stop(); $this->add($collected); $collector = end(static::$_collectors); if (!$collector) { return true; } $collector->add($mergeToParent ? $collected : []); $collector->_driver->start(); return true; }
[ "public", "function", "stop", "(", "$", "mergeToParent", "=", "true", ")", "{", "$", "collector", "=", "end", "(", "static", "::", "$", "_collectors", ")", ";", "if", "(", "$", "collector", "!==", "$", "this", ")", "{", "return", "false", ";", "}", ...
Stops collecting coverage data. @return boolean
[ "Stops", "collecting", "coverage", "data", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Collector.php#L179-L196
train
kahlan/kahlan
src/Reporter/Coverage/Collector.php
Collector.collectable
public function collectable($file) { $file = $this->realpath($file); if (preg_match("/eval\(\)'d code$/", $file) || !isset($this->_coverage[$file])) { return false; } return true; }
php
public function collectable($file) { $file = $this->realpath($file); if (preg_match("/eval\(\)'d code$/", $file) || !isset($this->_coverage[$file])) { return false; } return true; }
[ "public", "function", "collectable", "(", "$", "file", ")", "{", "$", "file", "=", "$", "this", "->", "realpath", "(", "$", "file", ")", ";", "if", "(", "preg_match", "(", "\"/eval\\(\\)'d code$/\"", ",", "$", "file", ")", "||", "!", "isset", "(", "$...
Checks if a filename is collectable. @param string $file A file path. @return boolean
[ "Checks", "if", "a", "filename", "is", "collectable", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Collector.php#L287-L294
train
kahlan/kahlan
src/Reporter/Coverage/Collector.php
Collector.realpath
public function realpath($file) { $prefix = preg_quote($this->_prefix, '~'); $file = preg_replace("~^{$prefix}~", '', $file); if (!$this->_hasVolume) { return $file; } if (preg_match('~^[A-Z]+:~', $file)) { return $file; } $file = ltrim($file, DS); $pos = strpos($file, DS); if ($pos !== false) { $file = substr_replace($file, ':' . DS, $pos, 1); } return $file; }
php
public function realpath($file) { $prefix = preg_quote($this->_prefix, '~'); $file = preg_replace("~^{$prefix}~", '', $file); if (!$this->_hasVolume) { return $file; } if (preg_match('~^[A-Z]+:~', $file)) { return $file; } $file = ltrim($file, DS); $pos = strpos($file, DS); if ($pos !== false) { $file = substr_replace($file, ':' . DS, $pos, 1); } return $file; }
[ "public", "function", "realpath", "(", "$", "file", ")", "{", "$", "prefix", "=", "preg_quote", "(", "$", "this", "->", "_prefix", ",", "'~'", ")", ";", "$", "file", "=", "preg_replace", "(", "\"~^{$prefix}~\"", ",", "''", ",", "$", "file", ")", ";",...
Gets the real path in the original src directory. @param string $file A file path or cached file path. @return string The original file path.
[ "Gets", "the", "real", "path", "in", "the", "original", "src", "directory", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Collector.php#L302-L318
train
kahlan/kahlan
src/Reporter/Coverage/Collector.php
Collector.export
public function export($file = null) { if ($file) { return isset($this->_coverage[$file]) ? $this->_coverage($file, $this->_coverage[$file]) : []; } $result = []; $base = preg_quote($this->base(), '~'); foreach ($this->_coverage as $file => $rawCoverage) { if ($coverage = $this->_coverage($file, $rawCoverage)) { $result[preg_replace("~^{$base}~", '', $file)] = $coverage; } } return $result; }
php
public function export($file = null) { if ($file) { return isset($this->_coverage[$file]) ? $this->_coverage($file, $this->_coverage[$file]) : []; } $result = []; $base = preg_quote($this->base(), '~'); foreach ($this->_coverage as $file => $rawCoverage) { if ($coverage = $this->_coverage($file, $rawCoverage)) { $result[preg_replace("~^{$base}~", '', $file)] = $coverage; } } return $result; }
[ "public", "function", "export", "(", "$", "file", "=", "null", ")", "{", "if", "(", "$", "file", ")", "{", "return", "isset", "(", "$", "this", "->", "_coverage", "[", "$", "file", "]", ")", "?", "$", "this", "->", "_coverage", "(", "$", "file", ...
Exports coverage data. @return array The coverage data.
[ "Exports", "coverage", "data", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Collector.php#L325-L338
train
kahlan/kahlan
src/Reporter/Coverage/Collector.php
Collector.metrics
public function metrics() { $this->_metrics = new Metrics(); foreach ($this->_coverage as $file => $rawCoverage) { $root = $this->parse($file); $coverage = $this->export($file); $this->_processed = [ 'loc' => -1, 'nlloc' => -1, 'lloc' => -1, 'cloc' => -1, 'coverage' => -1 ]; $this->_processTree($file, $root->tree, $coverage); } return $this->_metrics; }
php
public function metrics() { $this->_metrics = new Metrics(); foreach ($this->_coverage as $file => $rawCoverage) { $root = $this->parse($file); $coverage = $this->export($file); $this->_processed = [ 'loc' => -1, 'nlloc' => -1, 'lloc' => -1, 'cloc' => -1, 'coverage' => -1 ]; $this->_processTree($file, $root->tree, $coverage); } return $this->_metrics; }
[ "public", "function", "metrics", "(", ")", "{", "$", "this", "->", "_metrics", "=", "new", "Metrics", "(", ")", ";", "foreach", "(", "$", "this", "->", "_coverage", "as", "$", "file", "=>", "$", "rawCoverage", ")", "{", "$", "root", "=", "$", "this...
Gets the collected metrics from coverage data. @return Metrics The collected metrics.
[ "Gets", "the", "collected", "metrics", "from", "coverage", "data", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Collector.php#L345-L361
train
kahlan/kahlan
src/Reporter/Coverage/Collector.php
Collector.parse
public function parse($file) { if (isset($this->_tree[$file])) { return $this->_tree[$file]; } $parser = $this->_classes['parser']; return $this->_tree[$file] = $parser::parse(file_get_contents($file), ['lines' => true]); }
php
public function parse($file) { if (isset($this->_tree[$file])) { return $this->_tree[$file]; } $parser = $this->_classes['parser']; return $this->_tree[$file] = $parser::parse(file_get_contents($file), ['lines' => true]); }
[ "public", "function", "parse", "(", "$", "file", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_tree", "[", "$", "file", "]", ")", ")", "{", "return", "$", "this", "->", "_tree", "[", "$", "file", "]", ";", "}", "$", "parser", "=", "...
Retruns & cache the tree structure of a file. @param string $file the file path to use for building the tree structure.
[ "Retruns", "&", "cache", "the", "tree", "structure", "of", "a", "file", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Collector.php#L489-L496
train
kahlan/kahlan
src/Plugin/Stub/Method.php
Method.closure
public function closure() { if ($this->_closures) { if (isset($this->_closures[$this->_returnIndex])) { $closure = $this->_closures[$this->_returnIndex++]; } else { $closure = end($this->_closures); } return $closure; } elseif (array_key_exists($this->_returnIndex, $this->_returns)) { $this->_return = $this->_returns[$this->_returnIndex++]; } else { $this->_return = $this->_returns ? end($this->_returns) : null; } return function () { return $this->_return; }; }
php
public function closure() { if ($this->_closures) { if (isset($this->_closures[$this->_returnIndex])) { $closure = $this->_closures[$this->_returnIndex++]; } else { $closure = end($this->_closures); } return $closure; } elseif (array_key_exists($this->_returnIndex, $this->_returns)) { $this->_return = $this->_returns[$this->_returnIndex++]; } else { $this->_return = $this->_returns ? end($this->_returns) : null; } return function () { return $this->_return; }; }
[ "public", "function", "closure", "(", ")", "{", "if", "(", "$", "this", "->", "_closures", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_closures", "[", "$", "this", "->", "_returnIndex", "]", ")", ")", "{", "$", "closure", "=", "$", "t...
Return a compatible callable. @return callable The callable.
[ "Return", "a", "compatible", "callable", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub/Method.php#L113-L130
train
kahlan/kahlan
src/Plugin/Stub/Method.php
Method.toBe
public function toBe() { if ($this->reference()) { $this->_substitutes = func_get_args(); } else { $this->_actsAsAReplacement = true; if (func_num_args() !== 1) { throw new Exception("Only one hard method substitution is allowed through `toBe()`."); } $this->_closures = func_get_args(); } }
php
public function toBe() { if ($this->reference()) { $this->_substitutes = func_get_args(); } else { $this->_actsAsAReplacement = true; if (func_num_args() !== 1) { throw new Exception("Only one hard method substitution is allowed through `toBe()`."); } $this->_closures = func_get_args(); } }
[ "public", "function", "toBe", "(", ")", "{", "if", "(", "$", "this", "->", "reference", "(", ")", ")", "{", "$", "this", "->", "_substitutes", "=", "func_get_args", "(", ")", ";", "}", "else", "{", "$", "this", "->", "_actsAsAReplacement", "=", "true...
Set return values. @param mixed ... <0,n> Return value(s).
[ "Set", "return", "values", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub/Method.php#L137-L148
train
kahlan/kahlan
src/Plugin/Stub/Method.php
Method.andRun
public function andRun() { if ($this->_returns) { throw new Exception("Some return value(s) has already been set."); } $closures = func_get_args(); foreach ($closures as $closure) { if (!is_callable($closure)) { throw new Exception("The passed parameter is not callable."); } } $this->_closures = $closures; }
php
public function andRun() { if ($this->_returns) { throw new Exception("Some return value(s) has already been set."); } $closures = func_get_args(); foreach ($closures as $closure) { if (!is_callable($closure)) { throw new Exception("The passed parameter is not callable."); } } $this->_closures = $closures; }
[ "public", "function", "andRun", "(", ")", "{", "if", "(", "$", "this", "->", "_returns", ")", "{", "throw", "new", "Exception", "(", "\"Some return value(s) has already been set.\"", ")", ";", "}", "$", "closures", "=", "func_get_args", "(", ")", ";", "forea...
Set the stub logic.
[ "Set", "the", "stub", "logic", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub/Method.php#L153-L165
train
kahlan/kahlan
src/Plugin/Stub/Method.php
Method.substitute
public function substitute() { if (isset($this->_substitutes[$this->_substituteIndex])) { return $this->_substitutes[$this->_substituteIndex++]; } return $this->_substitutes ? end($this->_substitutes) : null; }
php
public function substitute() { if (isset($this->_substitutes[$this->_substituteIndex])) { return $this->_substitutes[$this->_substituteIndex++]; } return $this->_substitutes ? end($this->_substitutes) : null; }
[ "public", "function", "substitute", "(", ")", "{", "if", "(", "isset", "(", "$", "this", "->", "_substitutes", "[", "$", "this", "->", "_substituteIndex", "]", ")", ")", "{", "return", "$", "this", "->", "_substitutes", "[", "$", "this", "->", "_substi...
Get the method substitute. @return mixed
[ "Get", "the", "method", "substitute", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Stub/Method.php#L196-L202
train
kahlan/kahlan
src/Plugin/Call/Calls.php
Calls.log
public static function log($reference, $call) { $calls = []; if (is_array($reference)) { foreach ($reference as $value) { $calls[] = static::_call($value, $call); } } else { $calls[] = static::_call($reference, $call); } static::$_logs[] = $calls; }
php
public static function log($reference, $call) { $calls = []; if (is_array($reference)) { foreach ($reference as $value) { $calls[] = static::_call($value, $call); } } else { $calls[] = static::_call($reference, $call); } static::$_logs[] = $calls; }
[ "public", "static", "function", "log", "(", "$", "reference", ",", "$", "call", ")", "{", "$", "calls", "=", "[", "]", ";", "if", "(", "is_array", "(", "$", "reference", ")", ")", "{", "foreach", "(", "$", "reference", "as", "$", "value", ")", "{...
Logs a call. @param mixed $reference An instance or a fully-namespaced class name or an array of them. @param string $call The method name.
[ "Logs", "a", "call", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Call/Calls.php#L28-L39
train
kahlan/kahlan
src/Plugin/Call/Calls.php
Calls.logs
public static function logs($reference = null, $index = 0) { if (!func_num_args()) { return static::$_logs; } $result = []; $count = count(static::$_logs); for ($i = $index; $i < $count; $i++) { $logs = static::$_logs[$i]; if ($log = static::_matchReference($reference, $logs)) { $result[] = $log; } } return $result; }
php
public static function logs($reference = null, $index = 0) { if (!func_num_args()) { return static::$_logs; } $result = []; $count = count(static::$_logs); for ($i = $index; $i < $count; $i++) { $logs = static::$_logs[$i]; if ($log = static::_matchReference($reference, $logs)) { $result[] = $log; } } return $result; }
[ "public", "static", "function", "logs", "(", "$", "reference", "=", "null", ",", "$", "index", "=", "0", ")", "{", "if", "(", "!", "func_num_args", "(", ")", ")", "{", "return", "static", "::", "$", "_logs", ";", "}", "$", "result", "=", "[", "]"...
Get all logs or all logs related to an instance or a fully-namespaced class name. @param object|string $reference An instance or a fully-namespaced class name. @param integer $index Start index. @return array The founded log calls.
[ "Get", "all", "logs", "or", "all", "logs", "related", "to", "an", "instance", "or", "a", "fully", "-", "namespaced", "class", "name", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Call/Calls.php#L73-L87
train
kahlan/kahlan
src/Plugin/Call/Calls.php
Calls.find
public static function find($message, $index = 0, $times = 0, &$args = []) { $success = false; $messages = !is_array($message) ? [$message] : $message; $message = reset($messages); $reference = $message->reference(); $reference = $message->isStatic() && is_object($reference) ? get_class($reference) : $reference; $lastFound = null; $count = count(static::$_logs); for ($i = $index; $i < $count; $i++) { $logs = static::$_logs[$i]; if (!$log = static::_matchReference($reference, $logs)) { continue; } if (!$message->match($log, false)) { continue; } $args[] = $log['args']; if (!$message->matchArgs($log['args'])) { continue; } if ($message = next($messages)) { $lastFound = $message; if (!$reference = $message->reference() && $log['method']) { $reference = $log['method']->actualReturn(); } if (!is_object($reference)) { $message = reset($messages); $reference = $message->reference(); } $reference = $message->isStatic() && is_object($reference) ? get_class($reference) : $reference; continue; } $times -= 1; if ($times < 0) { $success = true; static::find($messages, $i + 1, 0, $args); static::$_index = $i + 1; break; } elseif ($times === 0) { $next = static::find($messages, $i + 1, 0, $args); if ($next['success']) { $success = false; } else { $success = true; static::$_index = $i + 1; } break; } return static::find($messages, $i + 1, $times, $args); } $index = static::$_index; $message = $lastFound ?: reset($messages); return compact('success', 'message', 'args', 'index'); }
php
public static function find($message, $index = 0, $times = 0, &$args = []) { $success = false; $messages = !is_array($message) ? [$message] : $message; $message = reset($messages); $reference = $message->reference(); $reference = $message->isStatic() && is_object($reference) ? get_class($reference) : $reference; $lastFound = null; $count = count(static::$_logs); for ($i = $index; $i < $count; $i++) { $logs = static::$_logs[$i]; if (!$log = static::_matchReference($reference, $logs)) { continue; } if (!$message->match($log, false)) { continue; } $args[] = $log['args']; if (!$message->matchArgs($log['args'])) { continue; } if ($message = next($messages)) { $lastFound = $message; if (!$reference = $message->reference() && $log['method']) { $reference = $log['method']->actualReturn(); } if (!is_object($reference)) { $message = reset($messages); $reference = $message->reference(); } $reference = $message->isStatic() && is_object($reference) ? get_class($reference) : $reference; continue; } $times -= 1; if ($times < 0) { $success = true; static::find($messages, $i + 1, 0, $args); static::$_index = $i + 1; break; } elseif ($times === 0) { $next = static::find($messages, $i + 1, 0, $args); if ($next['success']) { $success = false; } else { $success = true; static::$_index = $i + 1; } break; } return static::find($messages, $i + 1, $times, $args); } $index = static::$_index; $message = $lastFound ?: reset($messages); return compact('success', 'message', 'args', 'index'); }
[ "public", "static", "function", "find", "(", "$", "message", ",", "$", "index", "=", "0", ",", "$", "times", "=", "0", ",", "&", "$", "args", "=", "[", "]", ")", "{", "$", "success", "=", "false", ";", "$", "messages", "=", "!", "is_array", "("...
Finds a logged call. @param object $message The message method name. @param integer $index Start index. @param integer $times @param array $args Populated by the list of passed arguments. @return array|false Return founded log call.
[ "Finds", "a", "logged", "call", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Plugin/Call/Calls.php#L112-L174
train
kahlan/kahlan
src/Reporter/Coverage/Exporter/Istanbul.php
Istanbul.export
public static function export($options) { $defaults = [ 'collector' => null, 'base_path' => getcwd() ]; $options += $defaults; $collector = $options['collector']; $export = []; $base = $options['base_path'] ? rtrim($options['base_path'], DS) . DS : ''; foreach ($collector->export() as $file => $coverage) { $path = $base . $file; $export[$path] = static::_export($path, $collector->parse($file), $coverage); } return json_encode($export); }
php
public static function export($options) { $defaults = [ 'collector' => null, 'base_path' => getcwd() ]; $options += $defaults; $collector = $options['collector']; $export = []; $base = $options['base_path'] ? rtrim($options['base_path'], DS) . DS : ''; foreach ($collector->export() as $file => $coverage) { $path = $base . $file; $export[$path] = static::_export($path, $collector->parse($file), $coverage); } return json_encode($export); }
[ "public", "static", "function", "export", "(", "$", "options", ")", "{", "$", "defaults", "=", "[", "'collector'", "=>", "null", ",", "'base_path'", "=>", "getcwd", "(", ")", "]", ";", "$", "options", "+=", "$", "defaults", ";", "$", "collector", "=", ...
Exports a coverage to a Istanbul compatible JSON format. @param array $options The option array where the possible values are: -`'collector'` _object_ : The collector instance. @return string
[ "Exports", "a", "coverage", "to", "a", "Istanbul", "compatible", "JSON", "format", "." ]
b0341a59cefd2697f6e104bbcf045ee36a189ea2
https://github.com/kahlan/kahlan/blob/b0341a59cefd2697f6e104bbcf045ee36a189ea2/src/Reporter/Coverage/Exporter/Istanbul.php#L36-L56
train
Victoire/victoire
Bundle/SeoBundle/Controller/Error404Controller.php
Error404Controller.returnAfterRemoval
private function returnAfterRemoval(Error404 $error404) { $em = $this->getDoctrine()->getManager(); /** @var HttpErrorRepository $errorRepository */ $errorRepository = $em->getRepository('VictoireSeoBundle:HttpError'); $errors = ($error404->getType() == HttpError::TYPE_ROUTE) ? $errorRepository->getRouteErrors() : $errorRepository->getFileErrors(); if (0 == count($errors->getQuery()->getResult())) { return new Response($this->renderView('@VictoireSeo/Error404/_empty.html.twig'), 200, [ 'X-Inject-Alertify' => true, ]); } return new Response(null, 200, [ 'X-VIC-Remove' => '100ms', 'X-Inject-Alertify' => true, ]); }
php
private function returnAfterRemoval(Error404 $error404) { $em = $this->getDoctrine()->getManager(); /** @var HttpErrorRepository $errorRepository */ $errorRepository = $em->getRepository('VictoireSeoBundle:HttpError'); $errors = ($error404->getType() == HttpError::TYPE_ROUTE) ? $errorRepository->getRouteErrors() : $errorRepository->getFileErrors(); if (0 == count($errors->getQuery()->getResult())) { return new Response($this->renderView('@VictoireSeo/Error404/_empty.html.twig'), 200, [ 'X-Inject-Alertify' => true, ]); } return new Response(null, 200, [ 'X-VIC-Remove' => '100ms', 'X-Inject-Alertify' => true, ]); }
[ "private", "function", "returnAfterRemoval", "(", "Error404", "$", "error404", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "/** @var HttpErrorRepository $errorRepository */", "$", "errorRepository", "=",...
Remove error if there is more than one record, else return _empty template. @param Error404 $error404 @return Response
[ "Remove", "error", "if", "there", "is", "more", "than", "one", "record", "else", "return", "_empty", "template", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/SeoBundle/Controller/Error404Controller.php#L158-L179
train
Victoire/victoire
Bundle/CoreBundle/Twig/Extension/RoutingExtension.php
RoutingExtension.getPrefix
protected function getPrefix($locale) { foreach ($this->localeResolver->getDomainConfig() as $_domain => $_locale) { if ($_locale === $locale) { $urlPrefix = sprintf('%s://%s', $this->request ? $this->request->getScheme() : 'http', $_domain); if ($this->request && $this->request->getPort()) { $urlPrefix .= ':'.$this->request->getPort(); } return $urlPrefix; } } }
php
protected function getPrefix($locale) { foreach ($this->localeResolver->getDomainConfig() as $_domain => $_locale) { if ($_locale === $locale) { $urlPrefix = sprintf('%s://%s', $this->request ? $this->request->getScheme() : 'http', $_domain); if ($this->request && $this->request->getPort()) { $urlPrefix .= ':'.$this->request->getPort(); } return $urlPrefix; } } }
[ "protected", "function", "getPrefix", "(", "$", "locale", ")", "{", "foreach", "(", "$", "this", "->", "localeResolver", "->", "getDomainConfig", "(", ")", "as", "$", "_domain", "=>", "$", "_locale", ")", "{", "if", "(", "$", "_locale", "===", "$", "lo...
If victoire_i18n.locale_pattern == domain, then we force the url rewrite with a valid host. @param $locale @return null
[ "If", "victoire_i18n", ".", "locale_pattern", "==", "domain", "then", "we", "force", "the", "url", "rewrite", "with", "a", "valid", "host", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/CoreBundle/Twig/Extension/RoutingExtension.php#L110-L122
train
Victoire/victoire
Bundle/TemplateBundle/Controller/TemplateController.php
TemplateController.newAction
public function newAction(Request $request) { $em = $this->getDoctrine()->getManager(); $template = new Template(); $form = $this->container->get('form.factory')->create(TemplateType::class, $template); $form->handleRequest($request); if ($form->isValid()) { $em->persist($template); $em->flush(); return new JsonResponse([ 'success' => true, 'url' => $this->generateUrl('victoire_template_show', ['id' => $template->getId()]), ]); } return new JsonResponse( [ 'success' => true, 'html' => $this->container->get('templating')->render( 'VictoireTemplateBundle:Template:new.html.twig', ['form' => $form->createView()] ), ] ); }
php
public function newAction(Request $request) { $em = $this->getDoctrine()->getManager(); $template = new Template(); $form = $this->container->get('form.factory')->create(TemplateType::class, $template); $form->handleRequest($request); if ($form->isValid()) { $em->persist($template); $em->flush(); return new JsonResponse([ 'success' => true, 'url' => $this->generateUrl('victoire_template_show', ['id' => $template->getId()]), ]); } return new JsonResponse( [ 'success' => true, 'html' => $this->container->get('templating')->render( 'VictoireTemplateBundle:Template:new.html.twig', ['form' => $form->createView()] ), ] ); }
[ "public", "function", "newAction", "(", "Request", "$", "request", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "template", "=", "new", "Template", "(", ")", ";", "$", "form", "=", "$...
create a new Template. @return JsonResponse @Route("/new", name="victoire_template_new") @Configuration\Template()
[ "create", "a", "new", "Template", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/TemplateBundle/Controller/TemplateController.php#L103-L129
train
Victoire/victoire
Bundle/TemplateBundle/Controller/TemplateController.php
TemplateController.editAction
public function editAction(Request $request, Template $template) { $em = $this->getDoctrine()->getManager(); $form = $this->container->get('form.factory')->create(TemplateType::class, $template); $form->handleRequest($request); if ($form->isValid()) { $em->persist($template); $em->flush(); return $this->redirect($this->generateUrl('victoire_template_show', ['id' => $template->getId()])); } return $this->redirect($this->generateUrl('victoire_template_settings', ['id' => $template->getId()])); }
php
public function editAction(Request $request, Template $template) { $em = $this->getDoctrine()->getManager(); $form = $this->container->get('form.factory')->create(TemplateType::class, $template); $form->handleRequest($request); if ($form->isValid()) { $em->persist($template); $em->flush(); return $this->redirect($this->generateUrl('victoire_template_show', ['id' => $template->getId()])); } return $this->redirect($this->generateUrl('victoire_template_settings', ['id' => $template->getId()])); }
[ "public", "function", "editAction", "(", "Request", "$", "request", ",", "Template", "$", "template", ")", "{", "$", "em", "=", "$", "this", "->", "getDoctrine", "(", ")", "->", "getManager", "(", ")", ";", "$", "form", "=", "$", "this", "->", "conta...
edit a Template. @param Template $template The Template to edit @return \Symfony\Component\HttpFoundation\RedirectResponse @Route("/edit/{slug}", name="victoire_template_edit") @Configuration\Template() @ParamConverter("template", class="VictoireTemplateBundle:Template")
[ "edit", "a", "Template", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/TemplateBundle/Controller/TemplateController.php#L179-L193
train
Victoire/victoire
Bundle/PageBundle/Handler/RedirectionHandler.php
RedirectionHandler.handleError
public function handleError($redirection, $error404) { if ($redirection) { $this->increaseCounter($redirection); return $redirection; } elseif ($error404) { $this->increaseCounter($error404); return $error404; } throw new NoResultException(); }
php
public function handleError($redirection, $error404) { if ($redirection) { $this->increaseCounter($redirection); return $redirection; } elseif ($error404) { $this->increaseCounter($error404); return $error404; } throw new NoResultException(); }
[ "public", "function", "handleError", "(", "$", "redirection", ",", "$", "error404", ")", "{", "if", "(", "$", "redirection", ")", "{", "$", "this", "->", "increaseCounter", "(", "$", "redirection", ")", ";", "return", "$", "redirection", ";", "}", "elsei...
Check if the Error and its associated Redirection exists, then increase the counter of the Error|Redirection. @param Redirection|null $redirection @param Error404|null $error404 @throws NoResultException @return Redirection|Error404
[ "Check", "if", "the", "Error", "and", "its", "associated", "Redirection", "exists", "then", "increase", "the", "counter", "of", "the", "Error|Redirection", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/PageBundle/Handler/RedirectionHandler.php#L41-L54
train
Victoire/victoire
Bundle/CriteriaBundle/DataSource/IsLoggedDataSource.php
IsLoggedDataSource.getLoggedStatus
public function getLoggedStatus() { if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) { return true; } elseif ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { return true; } return false; }
php
public function getLoggedStatus() { if ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_FULLY')) { return true; } elseif ($this->authorizationChecker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { return true; } return false; }
[ "public", "function", "getLoggedStatus", "(", ")", "{", "if", "(", "$", "this", "->", "authorizationChecker", "->", "isGranted", "(", "'IS_AUTHENTICATED_FULLY'", ")", ")", "{", "return", "true", ";", "}", "elseif", "(", "$", "this", "->", "authorizationChecker...
Check actual status of current user return true if logged false if not. @return bool
[ "Check", "actual", "status", "of", "current", "user", "return", "true", "if", "logged", "false", "if", "not", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/CriteriaBundle/DataSource/IsLoggedDataSource.php#L30-L39
train
Victoire/victoire
Bundle/CoreBundle/Builder/ViewCssBuilder.php
ViewCssBuilder.updateViewCss
public function updateViewCss($oldHash, View $view, array $widgets) { $this->removeCssFile($oldHash); $this->generateViewCss($view, $widgets); }
php
public function updateViewCss($oldHash, View $view, array $widgets) { $this->removeCssFile($oldHash); $this->generateViewCss($view, $widgets); }
[ "public", "function", "updateViewCss", "(", "$", "oldHash", ",", "View", "$", "view", ",", "array", "$", "widgets", ")", "{", "$", "this", "->", "removeCssFile", "(", "$", "oldHash", ")", ";", "$", "this", "->", "generateViewCss", "(", "$", "view", ","...
Update css by removing old file and writing new file. @param $oldHash @param View $view @param array $widgets
[ "Update", "css", "by", "removing", "old", "file", "and", "writing", "new", "file", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/CoreBundle/Builder/ViewCssBuilder.php#L46-L50
train
Victoire/victoire
Bundle/CoreBundle/Builder/ViewCssBuilder.php
ViewCssBuilder.generateViewCss
public function generateViewCss(View $view, array $widgets) { $css = ''; foreach ($widgets as $widget) { $style = $this->container->get('templating')->render( 'VictoireCoreBundle:Widget:style/style.html.twig', [ 'widget' => $widget, 'victoire_twig_responsive' => $this->victoireTwigResponsive, ] ); $css .= trim($style); } if ($css !== '') { $this->writeCssFile($view, $css); } }
php
public function generateViewCss(View $view, array $widgets) { $css = ''; foreach ($widgets as $widget) { $style = $this->container->get('templating')->render( 'VictoireCoreBundle:Widget:style/style.html.twig', [ 'widget' => $widget, 'victoire_twig_responsive' => $this->victoireTwigResponsive, ] ); $css .= trim($style); } if ($css !== '') { $this->writeCssFile($view, $css); } }
[ "public", "function", "generateViewCss", "(", "View", "$", "view", ",", "array", "$", "widgets", ")", "{", "$", "css", "=", "''", ";", "foreach", "(", "$", "widgets", "as", "$", "widget", ")", "{", "$", "style", "=", "$", "this", "->", "container", ...
Construct css file and write it. @param View $view @param array $widgets
[ "Construct", "css", "file", "and", "write", "it", "." ]
53c314c578dcf92adfb6538b27dbc7a2ec16f432
https://github.com/Victoire/victoire/blob/53c314c578dcf92adfb6538b27dbc7a2ec16f432/Bundle/CoreBundle/Builder/ViewCssBuilder.php#L58-L76
train