code
stringlengths
31
1.39M
docstring
stringlengths
23
16.8k
func_name
stringlengths
1
126
language
stringclasses
1 value
repo
stringlengths
7
63
path
stringlengths
7
166
url
stringlengths
50
220
license
stringclasses
7 values
public function isFirst(?int $gridWidth = null): bool { return $this->counter === 1 || ($gridWidth && $this->counter !== 0 && (($this->counter - 1) % $gridWidth) === 0); }
Is the current element the first one?
isFirst
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
BSD-3-Clause
public function isLast(?int $gridWidth = null): bool { return !$this->hasNext() || ($gridWidth && ($this->counter % $gridWidth) === 0); }
Is the current element the last one?
isLast
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Iterators/CachingIterator.php
BSD-3-Clause
public static function from(array $array, bool $recursive = true): static { $obj = new static; foreach ($array as $key => $value) { $obj->$key = $recursive && is_array($value) ? static::from($value) : $value; } return $obj; }
Transforms array to ArrayHash. @param array<T> $array
from
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
BSD-3-Clause
public function &getIterator(): \Iterator { foreach ((array) $this as $key => $foo) { yield $key => $this->$key; } }
Returns an iterator over all items. @return \Iterator<array-key, T>
getIterator
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
BSD-3-Clause
public function offsetSet($key, $value): void { if (!is_scalar($key)) { // prevents null throw new Nette\InvalidArgumentException(sprintf('Key must be either a string or an integer, %s given.', get_debug_type($key))); } $this->$key = $value; }
Replaces or appends a item. @param array-key $key @param T $value
offsetSet
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
BSD-3-Clause
#[\ReturnTypeWillChange] public function offsetGet($key) { return $this->$key; }
Returns a item. @param array-key $key @return T
offsetGet
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
BSD-3-Clause
public function offsetExists($key): bool { return isset($this->$key); }
Determines whether a item exists. @param array-key $key
offsetExists
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
BSD-3-Clause
public function offsetUnset($key): void { unset($this->$key); }
Removes the element from this list. @param array-key $key
offsetUnset
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayHash.php
BSD-3-Clause
public static function from(array $array): static { if (!Arrays::isList($array)) { throw new Nette\InvalidArgumentException('Array is not valid list.'); } $obj = new static; $obj->list = $array; return $obj; }
Transforms array to ArrayList. @param list<T> $array
from
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
BSD-3-Clause
public function &getIterator(): \Iterator { foreach ($this->list as &$item) { yield $item; } }
Returns an iterator over all items. @return \Iterator<int, T>
getIterator
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
BSD-3-Clause
public function offsetSet($index, $value): void { if ($index === null) { $this->list[] = $value; } elseif (!is_int($index) || $index < 0 || $index >= count($this->list)) { throw new Nette\OutOfRangeException('Offset invalid or out of range'); } else { $this->list[$index] = $value; } }
Replaces or appends a item. @param int|null $index @param T $value @throws Nette\OutOfRangeException
offsetSet
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
BSD-3-Clause
public function offsetGet($index): mixed { if (!is_int($index) || $index < 0 || $index >= count($this->list)) { throw new Nette\OutOfRangeException('Offset invalid or out of range'); } return $this->list[$index]; }
Returns a item. @param int $index @return T @throws Nette\OutOfRangeException
offsetGet
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
BSD-3-Clause
public function offsetExists($index): bool { return is_int($index) && $index >= 0 && $index < count($this->list); }
Determines whether a item exists. @param int $index
offsetExists
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
BSD-3-Clause
public function offsetUnset($index): void { if (!is_int($index) || $index < 0 || $index >= count($this->list)) { throw new Nette\OutOfRangeException('Offset invalid or out of range'); } array_splice($this->list, $index, 1); }
Removes the element at the specified position in this list. @param int $index @throws Nette\OutOfRangeException
offsetUnset
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ArrayList.php
BSD-3-Clause
public static function get(array $array, string|int|array $key, mixed $default = null): mixed { foreach (is_array($key) ? $key : [$key] as $k) { if (is_array($array) && array_key_exists($k, $array)) { $array = $array[$k]; } else { if (func_num_args() < 3) { throw new Nette\InvalidArgumentException("Missing item '$k'."); } return $default; } } return $array; }
Returns item from array. If it does not exist, it throws an exception, unless a default value is set. @template T @param array<T> $array @param array-key|array-key[] $key @param ?T $default @return ?T @throws Nette\InvalidArgumentException if item does not exist and default value is not provided
get
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function &getRef(array &$array, string|int|array $key): mixed { foreach (is_array($key) ? $key : [$key] as $k) { if (is_array($array) || $array === null) { $array = &$array[$k]; } else { throw new Nette\InvalidArgumentException('Traversed item is not an array.'); } } return $array; }
Returns reference to array item. If the index does not exist, new one is created with value null. @template T @param array<T> $array @param array-key|array-key[] $key @return ?T @throws Nette\InvalidArgumentException if traversed item is not an array
getRef
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function mergeTree(array $array1, array $array2): array { $res = $array1 + $array2; foreach (array_intersect_key($array1, $array2) as $k => $v) { if (is_array($v) && is_array($array2[$k])) { $res[$k] = self::mergeTree($v, $array2[$k]); } } return $res; }
Recursively merges two fields. It is useful, for example, for merging tree structures. It behaves as the + operator for array, ie. it adds a key/value pair from the second array to the first one and retains the value from the first array in the case of a key collision. @template T1 @template T2 @param array<T1> $array1 @param array<T2> $array2 @return array<T1|T2>
mergeTree
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function getKeyOffset(array $array, string|int $key): ?int { return Helpers::falseToNull(array_search(self::toKey($key), array_keys($array), strict: true)); }
Returns zero-indexed position of given array key. Returns null if key is not found.
getKeyOffset
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function contains(array $array, mixed $value): bool { return in_array($value, $array, true); }
Tests an array for the presence of value.
contains
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function first(array $array, ?callable $predicate = null, ?callable $else = null): mixed { $key = self::firstKey($array, $predicate); return $key === null ? ($else ? $else() : null) : $array[$key]; }
Returns the first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null. @template K of int|string @template V @param array<K, V> $array @param ?callable(V, K, array<K, V>): bool $predicate @return ?V
first
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function last(array $array, ?callable $predicate = null, ?callable $else = null): mixed { $key = self::lastKey($array, $predicate); return $key === null ? ($else ? $else() : null) : $array[$key]; }
Returns the last item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null. @template K of int|string @template V @param array<K, V> $array @param ?callable(V, K, array<K, V>): bool $predicate @return ?V
last
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function firstKey(array $array, ?callable $predicate = null): int|string|null { if (!$predicate) { return array_key_first($array); } foreach ($array as $k => $v) { if ($predicate($v, $k, $array)) { return $k; } } return null; }
Returns the key of first item (matching the specified predicate if given) or null if there is no such item. @template K of int|string @template V @param array<K, V> $array @param ?callable(V, K, array<K, V>): bool $predicate @return ?K
firstKey
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function lastKey(array $array, ?callable $predicate = null): int|string|null { return $predicate ? self::firstKey(array_reverse($array, preserve_keys: true), $predicate) : array_key_last($array); }
Returns the key of last item (matching the specified predicate if given) or null if there is no such item. @template K of int|string @template V @param array<K, V> $array @param ?callable(V, K, array<K, V>): bool $predicate @return ?K
lastKey
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function insertBefore(array &$array, string|int|null $key, array $inserted): void { $offset = $key === null ? 0 : (int) self::getKeyOffset($array, $key); $array = array_slice($array, 0, $offset, preserve_keys: true) + $inserted + array_slice($array, $offset, count($array), preserve_keys: true); }
Inserts the contents of the $inserted array into the $array immediately after the $key. If $key is null (or does not exist), it is inserted at the beginning.
insertBefore
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function insertAfter(array &$array, string|int|null $key, array $inserted): void { if ($key === null || ($offset = self::getKeyOffset($array, $key)) === null) { $offset = count($array) - 1; } $array = array_slice($array, 0, $offset + 1, preserve_keys: true) + $inserted + array_slice($array, $offset + 1, count($array), preserve_keys: true); }
Inserts the contents of the $inserted array into the $array before the $key. If $key is null (or does not exist), it is inserted at the end.
insertAfter
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function grep( array $array, #[Language('RegExp')] string $pattern, bool|int $invert = false, ): array { $flags = $invert ? PREG_GREP_INVERT : 0; return Strings::pcre('preg_grep', [$pattern, $array, $flags]); }
Returns only those array items, which matches a regular expression $pattern. @param string[] $array @return string[]
grep
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function flatten(array $array, bool $preserveKeys = false): array { $res = []; $cb = $preserveKeys ? function ($v, $k) use (&$res): void { $res[$k] = $v; } : function ($v) use (&$res): void { $res[] = $v; }; array_walk_recursive($array, $cb); return $res; }
Transforms multidimensional array to flat array.
flatten
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function isList(mixed $value): bool { return is_array($value) && ( PHP_VERSION_ID < 80100 ? !$value || array_keys($value) === range(0, count($value) - 1) : array_is_list($value) ); }
Checks if the array is indexed in ascending order of numeric keys from zero, a.k.a list. @return ($value is list ? true : false)
isList
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function associate(array $array, $path): array|\stdClass { $parts = is_array($path) ? $path : preg_split('#(\[\]|->|=|\|)#', $path, -1, PREG_SPLIT_DELIM_CAPTURE | PREG_SPLIT_NO_EMPTY); if (!$parts || $parts === ['->'] || $parts[0] === '=' || $parts[0] === '|') { throw new Nette\InvalidArgumentException("Invalid path '$path'."); } $res = $parts[0] === '->' ? new \stdClass : []; foreach ($array as $rowOrig) { $row = (array) $rowOrig; $x = &$res; for ($i = 0; $i < count($parts); $i++) { $part = $parts[$i]; if ($part === '[]') { $x = &$x[]; } elseif ($part === '=') { if (isset($parts[++$i])) { $x = $row[$parts[$i]]; $row = null; } } elseif ($part === '->') { if (isset($parts[++$i])) { if ($x === null) { $x = new \stdClass; } $x = &$x->{$row[$parts[$i]]}; } else { $row = is_object($rowOrig) ? $rowOrig : (object) $row; } } elseif ($part !== '|') { $x = &$x[(string) $row[$part]]; } } if ($x === null) { $x = $row; } } return $res; }
Reformats table to associative tree. Path looks like 'field|field[]field->field=field'. @param string|string[] $path
associate
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function normalize(array $array, mixed $filling = null): array { $res = []; foreach ($array as $k => $v) { $res[is_int($k) ? $v : $k] = is_int($k) ? $filling : $v; } return $res; }
Normalizes array to associative array. Replace numeric keys with their values, the new value will be $filling.
normalize
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function pick(array &$array, string|int $key, mixed $default = null): mixed { if (array_key_exists($key, $array)) { $value = $array[$key]; unset($array[$key]); return $value; } elseif (func_num_args() < 3) { throw new Nette\InvalidArgumentException("Missing item '$key'."); } else { return $default; } }
Returns and removes the value of an item from an array. If it does not exist, it throws an exception, or returns $default, if provided. @template T @param array<T> $array @param ?T $default @return ?T @throws Nette\InvalidArgumentException if item does not exist and default value is not provided
pick
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function some(iterable $array, callable $predicate): bool { foreach ($array as $k => $v) { if ($predicate($v, $k, $array)) { return true; } } return false; }
Tests whether at least one element in the array passes the test implemented by the provided function. @template K of int|string @template V @param array<K, V> $array @param callable(V, K, array<K, V>): bool $predicate
some
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function every(iterable $array, callable $predicate): bool { foreach ($array as $k => $v) { if (!$predicate($v, $k, $array)) { return false; } } return true; }
Tests whether all elements in the array pass the test implemented by the provided function. @template K of int|string @template V @param array<K, V> $array @param callable(V, K, array<K, V>): bool $predicate
every
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function filter(array $array, callable $predicate): array { $res = []; foreach ($array as $k => $v) { if ($predicate($v, $k, $array)) { $res[$k] = $v; } } return $res; }
Returns a new array containing all key-value pairs matching the given $predicate. @template K of int|string @template V @param array<K, V> $array @param callable(V, K, array<K, V>): bool $predicate @return array<K, V>
filter
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function map(iterable $array, callable $transformer): array { $res = []; foreach ($array as $k => $v) { $res[$k] = $transformer($v, $k, $array); } return $res; }
Returns an array containing the original keys and results of applying the given transform function to each element. @template K of int|string @template V @template R @param array<K, V> $array @param callable(V, K, array<K, V>): R $transformer @return array<K, R>
map
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function mapWithKeys(array $array, callable $transformer): array { $res = []; foreach ($array as $k => $v) { $pair = $transformer($v, $k, $array); if ($pair) { $res[$pair[0]] = $pair[1]; } } return $res; }
Returns an array containing new keys and values generated by applying the given transform function to each element. If the function returns null, the element is skipped. @template K of int|string @template V @template ResK of int|string @template ResV @param array<K, V> $array @param callable(V, K, array<K, V>): ?array{ResK, ResV} $transformer @return array<ResK, ResV>
mapWithKeys
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function invoke(iterable $callbacks, ...$args): array { $res = []; foreach ($callbacks as $k => $cb) { $res[$k] = $cb(...$args); } return $res; }
Invokes all callbacks and returns array of results. @param callable[] $callbacks
invoke
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function invokeMethod(iterable $objects, string $method, ...$args): array { $res = []; foreach ($objects as $k => $obj) { $res[$k] = $obj->$method(...$args); } return $res; }
Invokes method on every object in an array and returns array of results. @param object[] $objects
invokeMethod
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function toObject(iterable $array, object $object): object { foreach ($array as $k => $v) { $object->$k = $v; } return $object; }
Copies the elements of the $array array to the $object object and then returns it. @template T of object @param T $object @return T
toObject
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function wrap(array $array, string $prefix = '', string $suffix = ''): array { $res = []; foreach ($array as $k => $v) { $res[$k] = $prefix . $v . $suffix; } return $res; }
Returns copy of the $array where every item is converted to string and prefixed by $prefix and suffixed by $suffix. @param string[] $array @return string[]
wrap
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Arrays.php
BSD-3-Clause
public static function invokeSafe(string $function, array $args, callable $onError): mixed { $prev = set_error_handler(function ($severity, $message, $file) use ($onError, &$prev, $function): ?bool { if ($file === __FILE__) { $msg = ini_get('html_errors') ? Html::htmlToText($message) : $message; $msg = preg_replace("#^$function\\(.*?\\): #", '', $msg); if ($onError($msg, $severity) !== false) { return null; } } return $prev ? $prev(...func_get_args()) : false; }); try { return $function(...$args); } finally { restore_error_handler(); } }
Invokes internal PHP function with own error handler.
invokeSafe
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
BSD-3-Clause
public static function check(mixed $callable, bool $syntax = false) { if (!is_callable($callable, $syntax)) { throw new Nette\InvalidArgumentException( $syntax ? 'Given value is not a callable type.' : sprintf("Callback '%s' is not callable.", self::toString($callable)), ); } return $callable; }
Checks that $callable is valid PHP callback. Otherwise throws exception. If the $syntax is set to true, only verifies that $callable has a valid structure to be used as a callback, but does not verify if the class or method actually exists. @return callable @throws Nette\InvalidArgumentException
check
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
BSD-3-Clause
public static function toString(mixed $callable): string { if ($callable instanceof \Closure) { $inner = self::unwrap($callable); return '{closure' . ($inner instanceof \Closure ? '}' : ' ' . self::toString($inner) . '}'); } else { is_callable(is_object($callable) ? [$callable, '__invoke'] : $callable, true, $textual); return $textual; } }
Converts PHP callback to textual form. Class or method may not exists.
toString
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
BSD-3-Clause
public static function toReflection($callable): \ReflectionMethod|\ReflectionFunction { if ($callable instanceof \Closure) { $callable = self::unwrap($callable); } if (is_string($callable) && str_contains($callable, '::')) { return new ReflectionMethod(...explode('::', $callable, 2)); } elseif (is_array($callable)) { return new ReflectionMethod($callable[0], $callable[1]); } elseif (is_object($callable) && !$callable instanceof \Closure) { return new ReflectionMethod($callable, '__invoke'); } else { return new \ReflectionFunction($callable); } }
Returns reflection for method or function used in PHP callback. @param callable $callable type check is escalated to ReflectionException @throws \ReflectionException if callback is not valid
toReflection
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
BSD-3-Clause
public static function isStatic(callable $callable): bool { return is_string(is_array($callable) ? $callable[0] : $callable); }
Checks whether PHP callback is function or static method.
isStatic
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
BSD-3-Clause
public static function unwrap(\Closure $closure): callable|array { $r = new \ReflectionFunction($closure); $class = $r->getClosureScopeClass()?->name; if (str_ends_with($r->name, '}')) { return $closure; } elseif (($obj = $r->getClosureThis()) && $obj::class === $class) { return [$obj, $r->name]; } elseif ($class) { return [$class, $r->name]; } else { return $r->name; } }
Unwraps closure created by Closure::fromCallable().
unwrap
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Callback.php
BSD-3-Clause
public static function from(string|int|\DateTimeInterface|null $time): static { if ($time instanceof \DateTimeInterface) { return new static($time->format('Y-m-d H:i:s.u'), $time->getTimezone()); } elseif (is_numeric($time)) { if ($time <= self::YEAR) { $time += time(); } return (new static)->setTimestamp((int) $time); } else { // textual or null return new static((string) $time); } }
Creates a DateTime object from a string, UNIX timestamp, or other DateTimeInterface object. @throws \Exception if the date and time are not valid.
from
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
BSD-3-Clause
public static function fromParts( int $year, int $month, int $day, int $hour = 0, int $minute = 0, float $second = 0.0, ): static { $s = sprintf('%04d-%02d-%02d %02d:%02d:%02.5F', $year, $month, $day, $hour, $minute, $second); if ( !checkdate($month, $day, $year) || $hour < 0 || $hour > 23 || $minute < 0 || $minute > 59 || $second < 0 || $second >= 60 ) { throw new Nette\InvalidArgumentException("Invalid date '$s'"); } return new static($s); }
Creates DateTime object. @throws Nette\InvalidArgumentException if the date and time are not valid.
fromParts
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
BSD-3-Clause
public static function createFromFormat( string $format, string $time, string|\DateTimeZone|null $timezone = null, ): static|false { if ($timezone === null) { $timezone = new \DateTimeZone(date_default_timezone_get()); } elseif (is_string($timezone)) { $timezone = new \DateTimeZone($timezone); } $date = parent::createFromFormat($format, $time, $timezone); return $date ? static::from($date) : false; }
Returns new DateTime object formatted according to the specified format.
createFromFormat
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
BSD-3-Clause
public function jsonSerialize(): string { return $this->format('c'); }
Returns JSON representation in ISO 8601 (used by JavaScript).
jsonSerialize
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
BSD-3-Clause
public function __toString(): string { return $this->format('Y-m-d H:i:s'); }
Returns the date and time in the format 'Y-m-d H:i:s'.
__toString
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
BSD-3-Clause
public function modifyClone(string $modify = ''): static { $dolly = clone $this; return $modify ? $dolly->modify($modify) : $dolly; }
You'd better use: (clone $dt)->modify(...)
modifyClone
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/DateTime.php
BSD-3-Clause
public function getRelativePathname(): string { return ($this->relativePath === '' ? '' : $this->relativePath . DIRECTORY_SEPARATOR) . $this->getBasename(); }
Returns the relative path including file name.
getRelativePathname
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
BSD-3-Clause
public function read(): string { return FileSystem::read($this->getPathname()); }
Returns the contents of the file. @throws Nette\IOException
read
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
BSD-3-Clause
public function write(string $content): void { FileSystem::write($this->getPathname(), $content); }
Writes the contents to the file. @throws Nette\IOException
write
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileInfo.php
BSD-3-Clause
public static function createDir(string $dir, int $mode = 0777): void { if (!is_dir($dir) && !@mkdir($dir, $mode, recursive: true) && !is_dir($dir)) { // @ - dir may already exist throw new Nette\IOException(sprintf( "Unable to create directory '%s' with mode %s. %s", self::normalizePath($dir), decoct($mode), Helpers::getLastError(), )); } }
Creates a directory if it does not exist, including parent directories. @throws Nette\IOException on error occurred
createDir
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function copy(string $origin, string $target, bool $overwrite = true): void { if (stream_is_local($origin) && !file_exists($origin)) { throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($origin))); } elseif (!$overwrite && file_exists($target)) { throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", self::normalizePath($target))); } elseif (is_dir($origin)) { static::createDir($target); foreach (new \FilesystemIterator($target) as $item) { static::delete($item->getPathname()); } foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator($origin, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) { if ($item->isDir()) { static::createDir($target . '/' . $iterator->getSubPathName()); } else { static::copy($item->getPathname(), $target . '/' . $iterator->getSubPathName()); } } } else { static::createDir(dirname($target)); if (@stream_copy_to_stream(static::open($origin, 'rb'), static::open($target, 'wb')) === false) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to copy file '%s' to '%s'. %s", self::normalizePath($origin), self::normalizePath($target), Helpers::getLastError(), )); } } }
Copies a file or an entire directory. Overwrites existing files and directories by default. @throws Nette\IOException on error occurred @throws Nette\InvalidStateException if $overwrite is set to false and destination already exists
copy
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function open(string $path, string $mode) { $f = @fopen($path, $mode); // @ is escalated to exception if (!$f) { throw new Nette\IOException(sprintf( "Unable to open file '%s'. %s", self::normalizePath($path), Helpers::getLastError(), )); } return $f; }
Opens file and returns resource. @return resource @throws Nette\IOException on error occurred
open
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function delete(string $path): void { if (is_file($path) || is_link($path)) { $func = DIRECTORY_SEPARATOR === '\\' && is_dir($path) ? 'rmdir' : 'unlink'; if (!@$func($path)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to delete '%s'. %s", self::normalizePath($path), Helpers::getLastError(), )); } } elseif (is_dir($path)) { foreach (new \FilesystemIterator($path) as $item) { static::delete($item->getPathname()); } if (!@rmdir($path)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to delete directory '%s'. %s", self::normalizePath($path), Helpers::getLastError(), )); } } }
Deletes a file or an entire directory if exists. If the directory is not empty, it deletes its contents first. @throws Nette\IOException on error occurred
delete
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function rename(string $origin, string $target, bool $overwrite = true): void { if (!$overwrite && file_exists($target)) { throw new Nette\InvalidStateException(sprintf("File or directory '%s' already exists.", self::normalizePath($target))); } elseif (!file_exists($origin)) { throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($origin))); } else { static::createDir(dirname($target)); if (realpath($origin) !== realpath($target)) { static::delete($target); } if (!@rename($origin, $target)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to rename file or directory '%s' to '%s'. %s", self::normalizePath($origin), self::normalizePath($target), Helpers::getLastError(), )); } } }
Renames or moves a file or a directory. Overwrites existing files and directories by default. @throws Nette\IOException on error occurred @throws Nette\InvalidStateException if $overwrite is set to false and destination already exists
rename
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function read(string $file): string { $content = @file_get_contents($file); // @ is escalated to exception if ($content === false) { throw new Nette\IOException(sprintf( "Unable to read file '%s'. %s", self::normalizePath($file), Helpers::getLastError(), )); } return $content; }
Reads the content of a file. @throws Nette\IOException on error occurred
read
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function readLines(string $file, bool $stripNewLines = true): \Generator { return (function ($f) use ($file, $stripNewLines) { $counter = 0; do { $line = Callback::invokeSafe('fgets', [$f], fn($error) => throw new Nette\IOException(sprintf( "Unable to read file '%s'. %s", self::normalizePath($file), $error, ))); if ($line === false) { fclose($f); break; } if ($stripNewLines) { $line = rtrim($line, "\r\n"); } yield $counter++ => $line; } while (true); })(static::open($file, 'r')); }
Reads the file content line by line. Because it reads continuously as we iterate over the lines, it is possible to read files larger than the available memory. @return \Generator<int, string> @throws Nette\IOException on error occurred
readLines
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function write(string $file, string $content, ?int $mode = 0666): void { static::createDir(dirname($file)); if (@file_put_contents($file, $content) === false) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to write file '%s'. %s", self::normalizePath($file), Helpers::getLastError(), )); } if ($mode !== null && !@chmod($file, $mode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod file '%s' to mode %s. %s", self::normalizePath($file), decoct($mode), Helpers::getLastError(), )); } }
Writes the string to a file. @throws Nette\IOException on error occurred
write
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function makeWritable(string $path, int $dirMode = 0777, int $fileMode = 0666): void { if (is_file($path)) { if (!@chmod($path, $fileMode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod file '%s' to mode %s. %s", self::normalizePath($path), decoct($fileMode), Helpers::getLastError(), )); } } elseif (is_dir($path)) { foreach (new \FilesystemIterator($path) as $item) { static::makeWritable($item->getPathname(), $dirMode, $fileMode); } if (!@chmod($path, $dirMode)) { // @ is escalated to exception throw new Nette\IOException(sprintf( "Unable to chmod directory '%s' to mode %s. %s", self::normalizePath($path), decoct($dirMode), Helpers::getLastError(), )); } } else { throw new Nette\IOException(sprintf("File or directory '%s' not found.", self::normalizePath($path))); } }
Sets file permissions to `$fileMode` or directory permissions to `$dirMode`. Recursively traverses and sets permissions on the entire contents of the directory as well. @throws Nette\IOException on error occurred
makeWritable
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function isAbsolute(string $path): bool { return (bool) preg_match('#([a-z]:)?[/\\\]|[a-z][a-z0-9+.-]*://#Ai', $path); }
Determines if the path is absolute.
isAbsolute
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function normalizePath(string $path): string { $parts = $path === '' ? [] : preg_split('~[/\\\]+~', $path); $res = []; foreach ($parts as $part) { if ($part === '..' && $res && end($res) !== '..' && end($res) !== '') { array_pop($res); } elseif ($part !== '.') { $res[] = $part; } } return $res === [''] ? DIRECTORY_SEPARATOR : implode(DIRECTORY_SEPARATOR, $res); }
Normalizes `..` and `.` and directory separators in path.
normalizePath
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function joinPaths(string ...$paths): string { return self::normalizePath(implode('/', $paths)); }
Joins all segments of the path and normalizes the result.
joinPaths
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function resolvePath(string $basePath, string $path): string { return match (true) { self::isAbsolute($path) => self::platformSlashes($path), $path === '' => self::platformSlashes($basePath), default => self::joinPaths($basePath, $path), }; }
Resolves a path against a base path. If the path is absolute, returns it directly, if it's relative, joins it with the base path.
resolvePath
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function platformSlashes(string $path): string { return DIRECTORY_SEPARATOR === '/' ? strtr($path, '\\', '/') : str_replace(':\\\\', '://', strtr($path, '/', '\\')); // protocol:// }
Converts slashes to platform-specific directory separators.
platformSlashes
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/FileSystem.php
BSD-3-Clause
public static function find(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir')->addMask($masks, 'file'); }
Begins search for files and directories matching mask.
find
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public static function findFiles(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'file'); }
Begins search for files matching mask.
findFiles
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public static function findDirectories(string|array $masks = ['*']): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic return (new static)->addMask($masks, 'dir'); }
Begins search for directories matching mask.
findDirectories
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function files(string|array $masks = ['*']): static { return $this->addMask((array) $masks, 'file'); }
Finds files matching the specified masks.
files
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function directories(string|array $masks = ['*']): static { return $this->addMask((array) $masks, 'dir'); }
Finds directories matching the specified masks.
directories
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function in(string|array $paths): static { $paths = is_array($paths) ? $paths : func_get_args(); // compatibility with variadic $this->addLocation($paths, ''); return $this; }
Searches in the given directories. Wildcards are allowed.
in
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function from(string|array $paths): static { $paths = is_array($paths) ? $paths : func_get_args(); // compatibility with variadic $this->addLocation($paths, '/**'); return $this; }
Searches recursively from the given directories. Wildcards are allowed.
from
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function childFirst(bool $state = true): static { $this->childFirst = $state; return $this; }
Lists directory's contents before the directory itself. By default, this is disabled.
childFirst
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function ignoreUnreadableDirs(bool $state = true): static { $this->ignoreUnreadableDirs = $state; return $this; }
Ignores unreadable directories. By default, this is enabled.
ignoreUnreadableDirs
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function sortBy(callable $callback): static { $this->sort = $callback; return $this; }
Set a compare function for sorting directory entries. The function will be called to sort entries from the same directory. @param callable(FileInfo, FileInfo): int $callback
sortBy
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function sortByName(): static { $this->sort = fn(FileInfo $a, FileInfo $b): int => strnatcmp($a->getBasename(), $b->getBasename()); return $this; }
Sorts files in each directory naturally by name.
sortByName
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function append(string|array|null $paths = null): static { if ($paths === null) { return $this->appends[] = new static; } $this->appends = array_merge($this->appends, (array) $paths); return $this; }
Adds the specified paths or appends a new finder that returns.
append
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function exclude(string|array $masks): static { $masks = is_array($masks) ? $masks : func_get_args(); // compatibility with variadic foreach ($masks as $mask) { $mask = FileSystem::unixSlashes($mask); if (!preg_match('~^/?(\*\*/)?(.+)(/\*\*|/\*|/|)$~D', $mask, $m)) { throw new Nette\InvalidArgumentException("Invalid mask '$mask'"); } $end = $m[3]; $re = $this->buildPattern($m[2]); $filter = fn(FileInfo $file): bool => ($end && !$file->isDir()) || !preg_match($re, FileSystem::unixSlashes($file->getRelativePathname())); $this->descentFilter($filter); if ($end !== '/*') { $this->filter($filter); } } return $this; }
Skips entries that matches the given masks relative to the ones defined with the in() or from() methods.
exclude
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function filter(callable $callback): static { $this->filters[] = \Closure::fromCallable($callback); return $this; }
Yields only entries which satisfy the given filter. @param callable(FileInfo): bool $callback
filter
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function descentFilter(callable $callback): static { $this->descentFilters[] = \Closure::fromCallable($callback); return $this; }
It descends only to directories that match the specified filter. @param callable(FileInfo): bool $callback
descentFilter
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function limitDepth(?int $depth): static { $this->maxDepth = $depth ?? -1; return $this; }
Sets the maximum depth of entries.
limitDepth
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function size(string $operator, ?int $size = null): static { if (func_num_args() === 1) { // in $operator is predicate if (!preg_match('#^(?:([=<>!]=?|<>)\s*)?((?:\d*\.)?\d+)\s*(K|M|G|)B?$#Di', $operator, $matches)) { throw new Nette\InvalidArgumentException('Invalid size predicate format.'); } [, $operator, $size, $unit] = $matches; $units = ['' => 1, 'k' => 1e3, 'm' => 1e6, 'g' => 1e9]; $size *= $units[strtolower($unit)]; $operator = $operator ?: '='; } return $this->filter(fn(FileInfo $file): bool => !$file->isFile() || Helpers::compare($file->getSize(), $operator, $size)); }
Restricts the search by size. $operator accepts "[operator] [size] [unit]" example: >=10kB
size
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function date(string $operator, string|int|\DateTimeInterface|null $date = null): static { if (func_num_args() === 1) { // in $operator is predicate if (!preg_match('#^(?:([=<>!]=?|<>)\s*)?(.+)$#Di', $operator, $matches)) { throw new Nette\InvalidArgumentException('Invalid date predicate format.'); } [, $operator, $date] = $matches; $operator = $operator ?: '='; } $date = DateTime::from($date)->format('U'); return $this->filter(fn(FileInfo $file): bool => !$file->isFile() || Helpers::compare($file->getMTime(), $operator, $date)); }
Restricts the search by modified time. $operator accepts "[operator] [date]" example: >1978-01-23
date
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public function collect(): array { return iterator_to_array($this->getIterator(), preserve_keys: false); }
Returns an array with all found files and directories. @return list<FileInfo>
collect
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
private function traverseDir(string $dir, array $searches, array $subdirs = []): \Generator { if ($this->maxDepth >= 0 && count($subdirs) > $this->maxDepth) { return; } elseif (!is_dir($dir)) { throw new Nette\InvalidStateException(sprintf("Directory '%s' does not exist.", rtrim($dir, '/\\'))); } try { $pathNames = new \FilesystemIterator($dir, \FilesystemIterator::FOLLOW_SYMLINKS | \FilesystemIterator::SKIP_DOTS | \FilesystemIterator::CURRENT_AS_PATHNAME | \FilesystemIterator::UNIX_PATHS); } catch (\UnexpectedValueException $e) { if ($this->ignoreUnreadableDirs) { return; } else { throw new Nette\InvalidStateException($e->getMessage()); } } $files = $this->convertToFiles($pathNames, implode('/', $subdirs), FileSystem::isAbsolute($dir)); if ($this->sort) { $files = iterator_to_array($files); usort($files, $this->sort); } foreach ($files as $file) { $pathName = $file->getPathname(); $cache = $subSearch = []; if ($file->isDir()) { foreach ($searches as $search) { if ($search->recursive && $this->proveFilters($this->descentFilters, $file, $cache)) { $subSearch[] = $search; } } } if ($this->childFirst && $subSearch) { yield from $this->traverseDir($pathName, $subSearch, array_merge($subdirs, [$file->getBasename()])); } $relativePathname = FileSystem::unixSlashes($file->getRelativePathname()); foreach ($searches as $search) { if ( $file->{'is' . $search->mode}() && preg_match($search->pattern, $relativePathname) && $this->proveFilters($this->filters, $file, $cache) ) { yield $pathName => $file; break; } } if (!$this->childFirst && $subSearch) { yield from $this->traverseDir($pathName, $subSearch, array_merge($subdirs, [$file->getBasename()])); } } }
@param array<object{pattern: string, mode: string, recursive: bool}> $searches @param string[] $subdirs @return \Generator<string, FileInfo>
traverseDir
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
private function buildPlan(): array { $plan = $dirCache = []; foreach ($this->find as [$mask, $mode]) { $splits = []; if (FileSystem::isAbsolute($mask)) { if ($this->in) { throw new Nette\InvalidStateException("You cannot combine the absolute path in the mask '$mask' and the directory to search '{$this->in[0]}'."); } $splits[] = self::splitRecursivePart($mask); } else { foreach ($this->in ?: ['.'] as $in) { $in = strtr($in, ['[' => '[[]', ']' => '[]]']); // in path, do not treat [ and ] as a pattern by glob() $splits[] = self::splitRecursivePart($in . '/' . $mask); } } foreach ($splits as [$base, $rest, $recursive]) { $base = $base === '' ? '.' : $base; $dirs = $dirCache[$base] ??= strpbrk($base, '*?[') ? glob($base, GLOB_NOSORT | GLOB_ONLYDIR | GLOB_NOESCAPE) : [strtr($base, ['[[]' => '[', '[]]' => ']'])]; // unescape [ and ] if (!$dirs) { throw new Nette\InvalidStateException(sprintf("Directory '%s' does not exist.", rtrim($base, '/\\'))); } $search = (object) ['pattern' => $this->buildPattern($rest), 'mode' => $mode, 'recursive' => $recursive]; foreach ($dirs as $dir) { $plan[$dir][] = $search; } } } return $plan; }
@return array<string, array<object{pattern: string, mode: string, recursive: bool}>>
buildPlan
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
private static function splitRecursivePart(string $path): array { $a = strrpos($path, '/'); $parts = preg_split('~(?<=^|/)\*\*($|/)~', substr($path, 0, $a + 1), 2); return isset($parts[1]) ? [$parts[0], $parts[1] . substr($path, $a + 1), true] : [$parts[0], substr($path, $a + 1), false]; }
Since glob() does not know ** wildcard, we divide the path into a part for glob and a part for manual traversal.
splitRecursivePart
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Finder.php
BSD-3-Clause
public static function compare(float $a, float $b): int { if (is_nan($a) || is_nan($b)) { throw new \LogicException('Trying to compare NAN'); } elseif (!is_finite($a) && !is_finite($b) && $a === $b) { return 0; } $diff = abs($a - $b); if (($diff < self::Epsilon || ($diff / max(abs($a), abs($b)) < self::Epsilon))) { return 0; } return $a < $b ? -1 : 1; }
Compare two floats. If $a < $b it returns -1, if they are equal it returns 0 and if $a > $b it returns 1 @throws \LogicException if one of parameters is NAN
compare
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function areEqual(float $a, float $b): bool { return self::compare($a, $b) === 0; }
Returns true if $a = $b @throws \LogicException if one of parameters is NAN
areEqual
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isLessThan(float $a, float $b): bool { return self::compare($a, $b) < 0; }
Returns true if $a < $b @throws \LogicException if one of parameters is NAN
isLessThan
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isLessThanOrEqualTo(float $a, float $b): bool { return self::compare($a, $b) <= 0; }
Returns true if $a <= $b @throws \LogicException if one of parameters is NAN
isLessThanOrEqualTo
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isGreaterThan(float $a, float $b): bool { return self::compare($a, $b) > 0; }
Returns true if $a > $b @throws \LogicException if one of parameters is NAN
isGreaterThan
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function isGreaterThanOrEqualTo(float $a, float $b): bool { return self::compare($a, $b) >= 0; }
Returns true if $a >= $b @throws \LogicException if one of parameters is NAN
isGreaterThanOrEqualTo
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Floats.php
BSD-3-Clause
public static function capture(callable $func): string { ob_start(function () {}); try { $func(); return ob_get_clean(); } catch (\Throwable $e) { ob_end_clean(); throw $e; } }
Executes a callback and returns the captured output as a string.
capture
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function getLastError(): string { $message = error_get_last()['message'] ?? ''; $message = ini_get('html_errors') ? Html::htmlToText($message) : $message; $message = preg_replace('#^\w+\(.*?\): #', '', $message); return $message; }
Returns the last occurred PHP error or an empty string if no error occurred. Unlike error_get_last(), it is nit affected by the PHP directive html_errors and always returns text, not HTML.
getLastError
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause
public static function falseToNull(mixed $value): mixed { return $value === false ? null : $value; }
Converts false to null, does not change other values.
falseToNull
php
sebastianbergmann/php-code-coverage
tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Helpers.php
BSD-3-Clause