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 getItemCount(): ?int { return $this->itemCount; }
Returns the total number of items. @return int<0, max>|null
getItemCount
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function getOffset(): int { return $this->getPageIndex() * $this->itemsPerPage; }
Returns the absolute index of the first item on current page. @return int<0, max>
getOffset
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function getCountdownOffset(): ?int { return $this->itemCount === null ? null : max(0, $this->itemCount - ($this->getPageIndex() + 1) * $this->itemsPerPage); }
Returns the absolute index of the first item on current page in countdown paging. @return int<0, max>|null
getCountdownOffset
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public function getLength(): int { return $this->itemCount === null ? $this->itemsPerPage : min($this->itemsPerPage, $this->itemCount - $this->getPageIndex() * $this->itemsPerPage); }
Returns the number of items on current page. @return int<0, max>
getLength
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
BSD-3-Clause
public static function generate(int $length = 10, string $charlist = '0-9a-z'): string { $charlist = preg_replace_callback( '#.-.#', fn(array $m): string => implode('', range($m[0][0], $m[0][2])), $charlist, ); $charlist = count_chars($charlist, mode: 3); $chLen = strlen($charlist); if ($length < 1) { throw new Nette\InvalidArgumentException('Length must be greater than zero.'); } elseif ($chLen < 2) { throw new Nette\InvalidArgumentException('Character list must contain at least two chars.'); } elseif (PHP_VERSION_ID >= 80300) { return (new Randomizer)->getBytesFromString($charlist, $length); } $res = ''; for ($i = 0; $i < $length; $i++) { $res .= $charlist[random_int(0, $chLen - 1)]; } return $res; }
Generates a random string of given length from characters specified in second argument. Supports intervals, such as `0-9` or `A-Z`.
generate
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Random.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Random.php
BSD-3-Clause
public static function isBuiltinType(string $type): bool { return Validators::isBuiltinType($type); }
@deprecated use Nette\Utils\Validator::isBuiltinType()
isBuiltinType
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
public static function isClassKeyword(string $name): bool { return Validators::isClassKeyword($name); }
@deprecated use Nette\Utils\Validator::isClassKeyword()
isClassKeyword
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
public static function getPropertyDeclaringClass(\ReflectionProperty $prop): \ReflectionClass { foreach ($prop->getDeclaringClass()->getTraits() as $trait) { if ($trait->hasProperty($prop->name) // doc-comment guessing as workaround for insufficient PHP reflection && $trait->getProperty($prop->name)->getDocComment() === $prop->getDocComment() ) { return self::getPropertyDeclaringClass($trait->getProperty($prop->name)); } } return $prop->getDeclaringClass(); }
Returns a reflection of a class or trait that contains a declaration of given property. Property can also be declared in the trait.
getPropertyDeclaringClass
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
public static function getMethodDeclaringMethod(\ReflectionMethod $method): \ReflectionMethod { // file & line guessing as workaround for insufficient PHP reflection $decl = $method->getDeclaringClass(); if ($decl->getFileName() === $method->getFileName() && $decl->getStartLine() <= $method->getStartLine() && $decl->getEndLine() >= $method->getEndLine() ) { return $method; } $hash = [$method->getFileName(), $method->getStartLine(), $method->getEndLine()]; if (($alias = $decl->getTraitAliases()[$method->name] ?? null) && ($m = new \ReflectionMethod(...explode('::', $alias, 2))) && $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()] ) { return self::getMethodDeclaringMethod($m); } foreach ($decl->getTraits() as $trait) { if ($trait->hasMethod($method->name) && ($m = $trait->getMethod($method->name)) && $hash === [$m->getFileName(), $m->getStartLine(), $m->getEndLine()] ) { return self::getMethodDeclaringMethod($m); } } return $method; }
Returns a reflection of a method that contains a declaration of $method. Usually, each method is its own declaration, but the body of the method can also be in the trait and under a different name.
getMethodDeclaringMethod
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
public static function areCommentsAvailable(): bool { static $res; return $res ?? $res = (bool) (new \ReflectionMethod(self::class, __FUNCTION__))->getDocComment(); }
Finds out if reflection has access to PHPdoc comments. Comments may not be available due to the opcode cache.
areCommentsAvailable
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
public static function expandClassName(string $name, \ReflectionClass $context): string { $lower = strtolower($name); if (empty($name)) { throw new Nette\InvalidArgumentException('Class name must not be empty.'); } elseif (Validators::isBuiltinType($lower)) { return $lower; } elseif ($lower === 'self' || $lower === 'static') { return $context->name; } elseif ($lower === 'parent') { return $context->getParentClass() ? $context->getParentClass()->name : 'parent'; } elseif ($name[0] === '\\') { // fully qualified name return ltrim($name, '\\'); } $uses = self::getUseStatements($context); $parts = explode('\\', $name, 2); if (isset($uses[$parts[0]])) { $parts[0] = $uses[$parts[0]]; return implode('\\', $parts); } elseif ($context->inNamespace()) { return $context->getNamespaceName() . '\\' . $name; } else { return $name; } }
Expands the name of the class to full name in the given context of given class. Thus, it returns how the PHP parser would understand $name if it were written in the body of the class $context. @throws Nette\InvalidArgumentException
expandClassName
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
public static function getUseStatements(\ReflectionClass $class): array { if ($class->isAnonymous()) { throw new Nette\NotImplementedException('Anonymous classes are not supported.'); } static $cache = []; if (!isset($cache[$name = $class->name])) { if ($class->isInternal()) { $cache[$name] = []; } else { $code = file_get_contents($class->getFileName()); $cache = self::parseUseStatements($code, $name) + $cache; } } return $cache[$name]; }
@return array<string, class-string> of [alias => class]
getUseStatements
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
private static function parseUseStatements(string $code, ?string $forClass = null): array { try { $tokens = \PhpToken::tokenize($code, TOKEN_PARSE); } catch (\ParseError $e) { trigger_error($e->getMessage(), E_USER_NOTICE); $tokens = []; } $namespace = $class = null; $classLevel = $level = 0; $res = $uses = []; $nameTokens = [T_STRING, T_NS_SEPARATOR, T_NAME_QUALIFIED, T_NAME_FULLY_QUALIFIED]; while ($token = current($tokens)) { next($tokens); switch ($token->id) { case T_NAMESPACE: $namespace = ltrim(self::fetch($tokens, $nameTokens) . '\\', '\\'); $uses = []; break; case T_CLASS: case T_INTERFACE: case T_TRAIT: case PHP_VERSION_ID < 80100 ? T_CLASS : T_ENUM: if ($name = self::fetch($tokens, T_STRING)) { $class = $namespace . $name; $classLevel = $level + 1; $res[$class] = $uses; if ($class === $forClass) { return $res; } } break; case T_USE: while (!$class && ($name = self::fetch($tokens, $nameTokens))) { $name = ltrim($name, '\\'); if (self::fetch($tokens, '{')) { while ($suffix = self::fetch($tokens, $nameTokens)) { if (self::fetch($tokens, T_AS)) { $uses[self::fetch($tokens, T_STRING)] = $name . $suffix; } else { $tmp = explode('\\', $suffix); $uses[end($tmp)] = $name . $suffix; } if (!self::fetch($tokens, ',')) { break; } } } elseif (self::fetch($tokens, T_AS)) { $uses[self::fetch($tokens, T_STRING)] = $name; } else { $tmp = explode('\\', $name); $uses[end($tmp)] = $name; } if (!self::fetch($tokens, ',')) { break; } } break; case T_CURLY_OPEN: case T_DOLLAR_OPEN_CURLY_BRACES: case ord('{'): $level++; break; case ord('}'): if ($level === $classLevel) { $class = $classLevel = 0; } $level--; } } return $res; }
Parses PHP code to [class => [alias => class, ...]]
parseUseStatements
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
BSD-3-Clause
public static function checkEncoding(string $s): bool { return $s === self::fixEncoding($s); }
@deprecated use Nette\Utils\Validator::isUnicode()
checkEncoding
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function fixEncoding(string $s): string { // removes xD800-xDFFF, x110000 and higher return htmlspecialchars_decode(htmlspecialchars($s, ENT_NOQUOTES | ENT_IGNORE, 'UTF-8'), ENT_NOQUOTES); }
Removes all invalid UTF-8 characters from a string.
fixEncoding
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function chr(int $code): string { if ($code < 0 || ($code >= 0xD800 && $code <= 0xDFFF) || $code > 0x10FFFF) { throw new Nette\InvalidArgumentException('Code point must be in range 0x0 to 0xD7FF or 0xE000 to 0x10FFFF.'); } elseif (!extension_loaded('iconv')) { throw new Nette\NotSupportedException(__METHOD__ . '() requires ICONV extension that is not loaded.'); } return iconv('UTF-32BE', 'UTF-8//IGNORE', pack('N', $code)); }
Returns a specific character in UTF-8 from code point (number in range 0x0000..D7FF or 0xE000..10FFFF). @throws Nette\InvalidArgumentException if code point is not in valid range
chr
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function ord(string $c): int { if (!extension_loaded('iconv')) { throw new Nette\NotSupportedException(__METHOD__ . '() requires ICONV extension that is not loaded.'); } $tmp = iconv('UTF-8', 'UTF-32BE//IGNORE', $c); if (!$tmp) { throw new Nette\InvalidArgumentException('Invalid UTF-8 character "' . ($c === '' ? '' : '\x' . strtoupper(bin2hex($c))) . '".'); } return unpack('N', $tmp)[1]; }
Returns a code point of specific character in UTF-8 (number in range 0x0000..D7FF or 0xE000..10FFFF).
ord
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function substring(string $s, int $start, ?int $length = null): string { if (function_exists('mb_substr')) { return mb_substr($s, $start, $length, 'UTF-8'); // MB is much faster } elseif (!extension_loaded('iconv')) { throw new Nette\NotSupportedException(__METHOD__ . '() requires extension ICONV or MBSTRING, neither is loaded.'); } elseif ($length === null) { $length = self::length($s); } elseif ($start < 0 && $length < 0) { $start += self::length($s); // unifies iconv_substr behavior with mb_substr } return iconv_substr($s, $start, $length, 'UTF-8'); }
Returns a part of UTF-8 string specified by starting position and length. If start is negative, the returned string will start at the start'th character from the end of string.
substring
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function normalize(string $s): string { // convert to compressed normal form (NFC) if (class_exists('Normalizer', false) && ($n = \Normalizer::normalize($s, \Normalizer::FORM_C)) !== false) { $s = $n; } $s = self::unixNewLines($s); // remove control characters; leave \t + \n $s = self::pcre('preg_replace', ['#[\x00-\x08\x0B-\x1F\x7F-\x9F]+#u', '', $s]); // right trim $s = self::pcre('preg_replace', ['#[\t ]+$#m', '', $s]); // leading and trailing blank lines $s = trim($s, "\n"); return $s; }
Removes control characters, normalizes line breaks to `\n`, removes leading and trailing blank lines, trims end spaces on lines, normalizes UTF-8 to the normal form of NFC.
normalize
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function unixNewLines(string $s): string { return preg_replace("~\r\n?|\u{2028}|\u{2029}~", "\n", $s); }
Converts line endings to \n used on Unix-like systems. Line endings are: \n, \r, \r\n, U+2028 line separator, U+2029 paragraph separator.
unixNewLines
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function platformNewLines(string $s): string { return preg_replace("~\r\n?|\n|\u{2028}|\u{2029}~", PHP_EOL, $s); }
Converts line endings to platform-specific, i.e. \r\n on Windows and \n elsewhere. Line endings are: \n, \r, \r\n, U+2028 line separator, U+2029 paragraph separator.
platformNewLines
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function webalize(string $s, ?string $charlist = null, bool $lower = true): string { $s = self::toAscii($s); if ($lower) { $s = strtolower($s); } $s = self::pcre('preg_replace', ['#[^a-z0-9' . ($charlist !== null ? preg_quote($charlist, '#') : '') . ']+#i', '-', $s]); $s = trim($s, '-'); return $s; }
Modifies the UTF-8 string to the form used in the URL, ie removes diacritics and replaces all characters except letters of the English alphabet and numbers with a hyphens.
webalize
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function truncate(string $s, int $maxLen, string $append = "\u{2026}"): string { if (self::length($s) > $maxLen) { $maxLen -= self::length($append); if ($maxLen < 1) { return $append; } elseif ($matches = self::match($s, '#^.{1,' . $maxLen . '}(?=[\s\x00-/:-@\[-`{-~])#us')) { return $matches[0] . $append; } else { return self::substring($s, 0, $maxLen) . $append; } } return $s; }
Truncates a UTF-8 string to given maximal length, while trying not to split whole words. Only if the string is truncated, an ellipsis (or something else set with third argument) is appended to the string.
truncate
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function indent(string $s, int $level = 1, string $chars = "\t"): string { if ($level > 0) { $s = self::replace($s, '#(?:^|[\r\n]+)(?=[^\r\n])#', '$0' . str_repeat($chars, $level)); } return $s; }
Indents a multiline text from the left. Second argument sets how many indentation chars should be used, while the indent itself is the third argument (*tab* by default).
indent
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function lower(string $s): string { return mb_strtolower($s, 'UTF-8'); }
Converts all characters of UTF-8 string to lower case.
lower
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function firstLower(string $s): string { return self::lower(self::substring($s, 0, 1)) . self::substring($s, 1); }
Converts the first character of a UTF-8 string to lower case and leaves the other characters unchanged.
firstLower
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function upper(string $s): string { return mb_strtoupper($s, 'UTF-8'); }
Converts all characters of a UTF-8 string to upper case.
upper
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function firstUpper(string $s): string { return self::upper(self::substring($s, 0, 1)) . self::substring($s, 1); }
Converts the first character of a UTF-8 string to upper case and leaves the other characters unchanged.
firstUpper
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function capitalize(string $s): string { return mb_convert_case($s, MB_CASE_TITLE, 'UTF-8'); }
Converts the first character of every word of a UTF-8 string to upper case and the others to lower case.
capitalize
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function compare(string $left, string $right, ?int $length = null): bool { if (class_exists('Normalizer', false)) { $left = \Normalizer::normalize($left, \Normalizer::FORM_D); // form NFD is faster $right = \Normalizer::normalize($right, \Normalizer::FORM_D); // form NFD is faster } if ($length < 0) { $left = self::substring($left, $length, -$length); $right = self::substring($right, $length, -$length); } elseif ($length !== null) { $left = self::substring($left, 0, $length); $right = self::substring($right, 0, $length); } return self::lower($left) === self::lower($right); }
Compares two UTF-8 strings or their parts, without taking character case into account. If length is null, whole strings are compared, if it is negative, the corresponding number of characters from the end of the strings is compared, otherwise the appropriate number of characters from the beginning is compared.
compare
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function findPrefix(array $strings): string { $first = array_shift($strings); for ($i = 0; $i < strlen($first); $i++) { foreach ($strings as $s) { if (!isset($s[$i]) || $first[$i] !== $s[$i]) { while ($i && $first[$i - 1] >= "\x80" && $first[$i] >= "\x80" && $first[$i] < "\xC0") { $i--; } return substr($first, 0, $i); } } } return $first; }
Finds the common prefix of strings or returns empty string if the prefix was not found. @param string[] $strings
findPrefix
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function length(string $s): int { return match (true) { extension_loaded('mbstring') => mb_strlen($s, 'UTF-8'), extension_loaded('iconv') => iconv_strlen($s, 'UTF-8'), default => strlen(@utf8_decode($s)), // deprecated }; }
Returns number of characters (not bytes) in UTF-8 string. That is the number of Unicode code points which may differ from the number of graphemes.
length
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function trim(string $s, string $charlist = self::TrimCharacters): string { $charlist = preg_quote($charlist, '#'); return self::replace($s, '#^[' . $charlist . ']+|[' . $charlist . ']+$#Du', ''); }
Removes all left and right side spaces (or the characters passed as second argument) from a UTF-8 encoded string.
trim
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function padLeft(string $s, int $length, string $pad = ' '): string { $length = max(0, $length - self::length($s)); $padLen = self::length($pad); return str_repeat($pad, (int) ($length / $padLen)) . self::substring($pad, 0, $length % $padLen) . $s; }
Pads a UTF-8 string to given length by prepending the $pad string to the beginning. @param non-empty-string $pad
padLeft
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function padRight(string $s, int $length, string $pad = ' '): string { $length = max(0, $length - self::length($s)); $padLen = self::length($pad); return $s . str_repeat($pad, (int) ($length / $padLen)) . self::substring($pad, 0, $length % $padLen); }
Pads UTF-8 string to given length by appending the $pad string to the end. @param non-empty-string $pad
padRight
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function before(string $haystack, string $needle, int $nth = 1): ?string { $pos = self::pos($haystack, $needle, $nth); return $pos === null ? null : substr($haystack, 0, $pos); }
Returns part of $haystack before $nth occurence of $needle or returns null if the needle was not found. Negative value means searching from the end.
before
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function after(string $haystack, string $needle, int $nth = 1): ?string { $pos = self::pos($haystack, $needle, $nth); return $pos === null ? null : substr($haystack, $pos + strlen($needle)); }
Returns part of $haystack after $nth occurence of $needle or returns null if the needle was not found. Negative value means searching from the end.
after
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function indexOf(string $haystack, string $needle, int $nth = 1): ?int { $pos = self::pos($haystack, $needle, $nth); return $pos === null ? null : self::length(substr($haystack, 0, $pos)); }
Returns position in characters of $nth occurence of $needle in $haystack or null if the $needle was not found. Negative value of `$nth` means searching from the end.
indexOf
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
private static function pos(string $haystack, string $needle, int $nth = 1): ?int { if (!$nth) { return null; } elseif ($nth > 0) { if ($needle === '') { return 0; } $pos = 0; while (($pos = strpos($haystack, $needle, $pos)) !== false && --$nth) { $pos++; } } else { $len = strlen($haystack); if ($needle === '') { return $len; } elseif ($len === 0) { return null; } $pos = $len - 1; while (($pos = strrpos($haystack, $needle, $pos - $len)) !== false && ++$nth) { $pos--; } } return Helpers::falseToNull($pos); }
Returns position in characters of $nth occurence of $needle in $haystack or null if the needle was not found.
pos
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function split( string $subject, #[Language('RegExp')] string $pattern, bool|int $captureOffset = false, bool $skipEmpty = false, int $limit = -1, bool $utf8 = false, ): array { $flags = is_int($captureOffset) // back compatibility ? $captureOffset : ($captureOffset ? PREG_SPLIT_OFFSET_CAPTURE : 0) | ($skipEmpty ? PREG_SPLIT_NO_EMPTY : 0); $pattern .= $utf8 ? 'u' : ''; $m = self::pcre('preg_split', [$pattern, $subject, $limit, $flags | PREG_SPLIT_DELIM_CAPTURE]); return $utf8 && $captureOffset ? self::bytesToChars($subject, [$m])[0] : $m; }
Divides the string into arrays according to the regular expression. Expressions in parentheses will be captured and returned as well.
split
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function match( string $subject, #[Language('RegExp')] string $pattern, bool|int $captureOffset = false, int $offset = 0, bool $unmatchedAsNull = false, bool $utf8 = false, ): ?array { $flags = is_int($captureOffset) // back compatibility ? $captureOffset : ($captureOffset ? PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0); if ($utf8) { $offset = strlen(self::substring($subject, 0, $offset)); $pattern .= 'u'; } if ($offset > strlen($subject)) { return null; } elseif (!self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset])) { return null; } elseif ($utf8 && $captureOffset) { return self::bytesToChars($subject, [$m])[0]; } else { return $m; } }
Searches the string for the part matching the regular expression and returns an array with the found expression and individual subexpressions, or `null`.
match
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function matchAll( string $subject, #[Language('RegExp')] string $pattern, bool|int $captureOffset = false, int $offset = 0, bool $unmatchedAsNull = false, bool $patternOrder = false, bool $utf8 = false, bool $lazy = false, ): array|\Generator { if ($utf8) { $offset = strlen(self::substring($subject, 0, $offset)); $pattern .= 'u'; } if ($lazy) { $flags = PREG_OFFSET_CAPTURE | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0); return (function () use ($utf8, $captureOffset, $flags, $subject, $pattern, $offset) { $counter = 0; while ( $offset <= strlen($subject) - ($counter ? 1 : 0) && self::pcre('preg_match', [$pattern, $subject, &$m, $flags, $offset]) ) { $offset = $m[0][1] + max(1, strlen($m[0][0])); if (!$captureOffset) { $m = array_map(fn($item) => $item[0], $m); } elseif ($utf8) { $m = self::bytesToChars($subject, [$m])[0]; } yield $counter++ => $m; } })(); } if ($offset > strlen($subject)) { return []; } $flags = is_int($captureOffset) // back compatibility ? $captureOffset : ($captureOffset ? PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0) | ($patternOrder ? PREG_PATTERN_ORDER : 0); self::pcre('preg_match_all', [ $pattern, $subject, &$m, ($flags & PREG_PATTERN_ORDER) ? $flags : ($flags | PREG_SET_ORDER), $offset, ]); return $utf8 && $captureOffset ? self::bytesToChars($subject, $m) : $m; }
Searches the string for all occurrences matching the regular expression and returns an array of arrays containing the found expression and each subexpression. @return ($lazy is true ? \Generator<int, array> : array[])
matchAll
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function replace( string $subject, #[Language('RegExp')] string|array $pattern, string|callable $replacement = '', int $limit = -1, bool $captureOffset = false, bool $unmatchedAsNull = false, bool $utf8 = false, ): string { if (is_object($replacement) || is_array($replacement)) { if (!is_callable($replacement, false, $textual)) { throw new Nette\InvalidStateException("Callback '$textual' is not callable."); } $flags = ($captureOffset ? PREG_OFFSET_CAPTURE : 0) | ($unmatchedAsNull ? PREG_UNMATCHED_AS_NULL : 0); if ($utf8) { $pattern .= 'u'; if ($captureOffset) { $replacement = fn($m) => $replacement(self::bytesToChars($subject, [$m])[0]); } } return self::pcre('preg_replace_callback', [$pattern, $replacement, $subject, $limit, 0, $flags]); } elseif (is_array($pattern) && is_string(key($pattern))) { $replacement = array_values($pattern); $pattern = array_keys($pattern); } if ($utf8) { $pattern = array_map(fn($item) => $item . 'u', (array) $pattern); } return self::pcre('preg_replace', [$pattern, $replacement, $subject, $limit]); }
Replaces all occurrences matching regular expression $pattern which can be string or array in the form `pattern => replacement`.
replace
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
BSD-3-Clause
public static function fromReflection( \ReflectionFunctionAbstract|\ReflectionParameter|\ReflectionProperty $reflection, ): ?self { $type = $reflection instanceof \ReflectionFunctionAbstract ? $reflection->getReturnType() ?? (PHP_VERSION_ID >= 80100 && $reflection instanceof \ReflectionMethod ? $reflection->getTentativeReturnType() : null) : $reflection->getType(); return $type ? self::fromReflectionType($type, $reflection, asObject: true) : null; }
Creates a Type object based on reflection. Resolves self, static and parent to the actual class name. If the subject has no type, it returns null.
fromReflection
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public static function fromString(string $type): self { if (!Validators::isTypeDeclaration($type)) { throw new Nette\InvalidArgumentException("Invalid type '$type'."); } if ($type[0] === '?') { return new self([substr($type, 1), 'null']); } $unions = []; foreach (explode('|', $type) as $part) { $part = explode('&', trim($part, '()')); $unions[] = count($part) === 1 ? $part[0] : new self($part, '&'); } return count($unions) === 1 && $unions[0] instanceof self ? $unions[0] : new self($unions); }
Creates the Type object according to the text notation.
fromString
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public static function resolve( string $type, \ReflectionFunctionAbstract|\ReflectionParameter|\ReflectionProperty $of, ): string { $lower = strtolower($type); if ($of instanceof \ReflectionFunction) { return $type; } elseif ($lower === 'self') { return $of->getDeclaringClass()->name; } elseif ($lower === 'static') { return ($of instanceof ReflectionMethod ? $of->getOriginalClass() : $of->getDeclaringClass())->name; } elseif ($lower === 'parent' && $of->getDeclaringClass()->getParentClass()) { return $of->getDeclaringClass()->getParentClass()->name; } else { return $type; } }
Resolves 'self', 'static' and 'parent' to the actual class name.
resolve
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function getNames(): array { return array_map(fn($t) => $t instanceof self ? $t->getNames() : $t, $this->types); }
Returns the array of subtypes that make up the compound type as strings. @return array<int, string|string[]>
getNames
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function getTypes(): array { return array_map(fn($t) => $t instanceof self ? $t : new self([$t]), $this->types); }
Returns the array of subtypes that make up the compound type as Type objects: @return self[]
getTypes
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function getSingleName(): ?string { return $this->simple ? $this->types[0] : null; }
Returns the type name for simple types, otherwise null.
getSingleName
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function isUnion(): bool { return $this->kind === '|'; }
Returns true whether it is a union type.
isUnion
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function isIntersection(): bool { return $this->kind === '&'; }
Returns true whether it is an intersection type.
isIntersection
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function isSimple(): bool { return $this->simple; }
Returns true whether it is a simple type. Single nullable types are also considered to be simple types.
isSimple
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function isBuiltin(): bool { return $this->simple && Validators::isBuiltinType($this->types[0]); }
Returns true whether the type is both a simple and a PHP built-in type.
isBuiltin
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function isClass(): bool { return $this->simple && !Validators::isBuiltinType($this->types[0]); }
Returns true whether the type is both a simple and a class name.
isClass
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function isClassKeyword(): bool { return $this->simple && Validators::isClassKeyword($this->types[0]); }
Determines if type is special class name self/parent/static.
isClassKeyword
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public function allows(string $subtype): bool { if ($this->types === ['mixed']) { return true; } $subtype = self::fromString($subtype); return $subtype->isUnion() ? Arrays::every($subtype->types, fn($t) => $this->allows2($t instanceof self ? $t->types : [$t])) : $this->allows2($subtype->types); }
Verifies type compatibility. For example, it checks if a value of a certain type could be passed as a parameter.
allows
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Type.php
BSD-3-Clause
public static function assert(mixed $value, string $expected, string $label = 'variable'): void { if (!static::is($value, $expected)) { $expected = str_replace(['|', ':'], [' or ', ' in range '], $expected); $translate = ['boolean' => 'bool', 'integer' => 'int', 'double' => 'float', 'NULL' => 'null']; $type = $translate[gettype($value)] ?? gettype($value); if (is_int($value) || is_float($value) || (is_string($value) && strlen($value) < 40)) { $type .= ' ' . var_export($value, return: true); } elseif (is_object($value)) { $type .= ' ' . $value::class; } throw new AssertionException("The $label expects to be $expected, $type given."); } }
Verifies that the value is of expected types separated by pipe. @throws AssertionException
assert
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function assertField( array $array, $key, ?string $expected = null, string $label = "item '%' in array", ): void { if (!array_key_exists($key, $array)) { throw new AssertionException('Missing ' . str_replace('%', $key, $label) . '.'); } elseif ($expected) { static::assert($array[$key], $expected, str_replace('%', $key, $label)); } }
Verifies that element $key in array is of expected types separated by pipe. @param mixed[] $array @throws AssertionException
assertField
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function is(mixed $value, string $expected): bool { foreach (explode('|', $expected) as $item) { if (str_ends_with($item, '[]')) { if (is_iterable($value) && self::everyIs($value, substr($item, 0, -2))) { return true; } continue; } elseif (str_starts_with($item, '?')) { $item = substr($item, 1); if ($value === null) { return true; } } [$type] = $item = explode(':', $item, 2); if (isset(static::$validators[$type])) { try { if (!static::$validators[$type]($value)) { continue; } } catch (\TypeError $e) { continue; } } elseif ($type === 'pattern') { if (Strings::match($value, '|^' . ($item[1] ?? '') . '$|D')) { return true; } continue; } elseif (!$value instanceof $type) { continue; } if (isset($item[1])) { $length = $value; if (isset(static::$counters[$type])) { $length = static::$counters[$type]($value); } $range = explode('..', $item[1]); if (!isset($range[1])) { $range[1] = $range[0]; } if (($range[0] !== '' && $length < $range[0]) || ($range[1] !== '' && $length > $range[1])) { continue; } } return true; } return false; }
Verifies that the value is of expected types separated by pipe.
is
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function everyIs(iterable $values, string $expected): bool { foreach ($values as $value) { if (!static::is($value, $expected)) { return false; } } return true; }
Finds whether all values are of expected types separated by pipe. @param mixed[] $values
everyIs
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isNumber(mixed $value): bool { return is_int($value) || is_float($value); }
Checks if the value is an integer or a float. @return ($value is int|float ? true : false)
isNumber
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isNumericInt(mixed $value): bool { return is_int($value) || (is_string($value) && preg_match('#^[+-]?[0-9]+$#D', $value)); }
Checks if the value is an integer or a integer written in a string. @return ($value is non-empty-string ? bool : ($value is int ? true : false))
isNumericInt
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isNumeric(mixed $value): bool { return is_float($value) || is_int($value) || (is_string($value) && preg_match('#^[+-]?([0-9]++\.?[0-9]*|\.[0-9]+)$#D', $value)); }
Checks if the value is a number or a number written in a string. @return ($value is non-empty-string ? bool : ($value is int|float ? true : false))
isNumeric
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isCallable(mixed $value): bool { return $value && is_callable($value, syntax_only: true); }
Checks if the value is a syntactically correct callback.
isCallable
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isUnicode(mixed $value): bool { return is_string($value) && preg_match('##u', $value); }
Checks if the value is a valid UTF-8 string.
isUnicode
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isNone(mixed $value): bool { return $value == null; // intentionally == }
Checks if the value is 0, '', false or null. @return ($value is 0|''|false|null ? true : false)
isNone
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isList(mixed $value): bool { return Arrays::isList($value); }
Checks if a variable is a zero-based integer indexed array. @deprecated use Nette\Utils\Arrays::isList @return ($value is list ? true : false)
isList
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isEmail(string $value): bool { $atom = "[-a-z0-9!#$%&'*+/=?^_`{|}~]"; // RFC 5322 unquoted characters in local-part $alpha = "a-z\x80-\xFF"; // superset of IDN return (bool) preg_match(<<<XX (^(?n) ("([ !#-[\\]-~]*|\\\\[ -~])+"|$atom+(\\.$atom+)*) # quoted or unquoted @ ([0-9$alpha]([-0-9$alpha]{0,61}[0-9$alpha])?\\.)+ # domain - RFC 1034 [$alpha]([-0-9$alpha]{0,17}[$alpha])? # top domain $)Dix XX, $value); }
Checks if the value is a valid email address. It does not verify that the domain actually exists, only the syntax is verified.
isEmail
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isUrl(string $value): bool { $alpha = "a-z\x80-\xFF"; return (bool) preg_match(<<<XX (^(?n) https?://( (([-_0-9$alpha]+\\.)* # subdomain [0-9$alpha]([-0-9$alpha]{0,61}[0-9$alpha])?\\.)? # domain [$alpha]([-0-9$alpha]{0,17}[$alpha])? # top domain |\\d{1,3}\\.\\d{1,3}\\.\\d{1,3}\\.\\d{1,3} # IPv4 |\\[[0-9a-f:]{3,39}\\] # IPv6 )(:\\d{1,5})? # port (/\\S*)? # path (\\?\\S*)? # query (\\#\\S*)? # fragment $)Dix XX, $value); }
Checks if the value is a valid URL address.
isUrl
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isUri(string $value): bool { return (bool) preg_match('#^[a-z\d+\.-]+:\S+$#Di', $value); }
Checks if the value is a valid URI address, that is, actually a string beginning with a syntactically valid schema.
isUri
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isType(string $type): bool { return class_exists($type) || interface_exists($type) || trait_exists($type); }
Checks whether the input is a class, interface or trait. @deprecated
isType
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isPhpIdentifier(string $value): bool { return preg_match('#^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$#D', $value) === 1; }
Checks whether the input is a valid PHP identifier.
isPhpIdentifier
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isBuiltinType(string $type): bool { return isset(self::BuiltinTypes[strtolower($type)]); }
Determines if type is PHP built-in type. Otherwise, it is the class name.
isBuiltinType
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isClassKeyword(string $name): bool { return (bool) preg_match('#^(self|parent|static)$#Di', $name); }
Determines if type is special class name self/parent/static.
isClassKeyword
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
public static function isTypeDeclaration(string $type): bool { return (bool) preg_match(<<<'XX' ~((?n) \?? (?<type> \\? (?<name> [a-zA-Z_\x7f-\xff][\w\x7f-\xff]*) (\\ (?&name))* ) | (?<intersection> (?&type) (& (?&type))+ ) | (?<upart> (?&type) | \( (?&intersection) \) ) (\| (?&upart))+ )$~xAD XX, $type); }
Checks whether the given type declaration is syntactically valid.
isTypeDeclaration
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Validators.php
BSD-3-Clause
private function getParentConstructorClass($classReflection) { while ($classReflection->getParentClass() !== false) { $constructor = $classReflection->getParentClass()->hasMethod('__construct') ? $classReflection->getParentClass()->getMethod('__construct') : null; $constructorWithClassName = $classReflection->getParentClass()->hasMethod($classReflection->getParentClass()->getName()) ? $classReflection->getParentClass()->getMethod($classReflection->getParentClass()->getName()) : null; if ( ( $constructor !== null && $constructor->getDeclaringClass()->getName() === $classReflection->getParentClass()->getName() && !$constructor->isAbstract() && !$constructor->isPrivate() && !$constructor->isDeprecated() ) || ( $constructorWithClassName !== null && $constructorWithClassName->getDeclaringClass()->getName() === $classReflection->getParentClass()->getName() && !$constructorWithClassName->isAbstract() ) ) { return $classReflection->getParentClass(); } $classReflection = $classReflection->getParentClass(); } return false; }
@param ReflectionClass|ReflectionEnum $classReflection @return ReflectionClass|false
getParentConstructorClass
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/phpstan/phpstan-strict-rules/src/Rules/Classes/RequireParentConstructCallRule.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/phpstan/phpstan-strict-rules/src/Rules/Classes/RequireParentConstructCallRule.php
BSD-3-Clause
public function normalize(array $collectorDataByPath): TypeCountAndMissingTypes { $totalCount = 0; $missingCount = 0; $missingTypeLinesByFilePath = []; foreach ($collectorDataByPath as $filePath => $typeCoverageData) { foreach ($typeCoverageData as $nestedData) { $totalCount += $nestedData[0]; $missingCount += count($nestedData[1]); $missingTypeLinesByFilePath[$filePath] = array_merge( $missingTypeLinesByFilePath[$filePath] ?? [], $nestedData[1] ); } } return new TypeCountAndMissingTypes($totalCount, $missingCount, $missingTypeLinesByFilePath); }
@param array<string, array<array{0: int, 1: array<string, int>}>> $collectorDataByPath
normalize
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/tomasvotruba/type-coverage/src/CollectorDataNormalizer.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/tomasvotruba/type-coverage/src/CollectorDataNormalizer.php
BSD-3-Clause
public function processNode(Node $node, Scope $scope): ?array { if ($this->shouldSkipFunctionLike($node)) { return null; } $missingTypeLines = []; $paramCount = count($node->getParams()); foreach ($node->getParams() as $param) { if ($param->variadic) { // skip variadic --$paramCount; continue; } if ($param->type === null) { $missingTypeLines[] = $param->getLine(); } } return [$paramCount, $missingTypeLines]; }
@param FunctionLike $node @return mixed[]|null
processNode
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/tomasvotruba/type-coverage/src/Collectors/ParamTypeDeclarationCollector.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/tomasvotruba/type-coverage/src/Collectors/ParamTypeDeclarationCollector.php
BSD-3-Clause
public function processNode(Node $node, Scope $scope): ?array { // skip magic if ($node->isMagic()) { return null; } if ($scope->isInTrait()) { $originalMethodName = $node->getAttribute('originalTraitMethodName'); if ($originalMethodName === '__construct') { return null; } } $missingTypeLines = []; if (! $node->returnType instanceof Node) { $missingTypeLines[] = $node->getLine(); } return [1, $missingTypeLines]; }
@param ClassMethod $node @return mixed[]|null
processNode
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/tomasvotruba/type-coverage/src/Collectors/ReturnTypeDeclarationCollector.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/tomasvotruba/type-coverage/src/Collectors/ReturnTypeDeclarationCollector.php
BSD-3-Clause
public function formatErrors( string $message, string $identifier, $minimalLevel, TypeCountAndMissingTypes $typeCountAndMissingTypes ): array { if ($typeCountAndMissingTypes->getTotalCount() === 0) { return []; } $typeCoveragePercentage = $typeCountAndMissingTypes->getCoveragePercentage(); // has the code met the minimal sea level of types? if ($typeCoveragePercentage >= $minimalLevel) { return []; } $ruleErrors = []; foreach ($typeCountAndMissingTypes->getMissingTypeLinesByFilePath() as $filePath => $lines) { $errorMessage = sprintf( $message, $typeCountAndMissingTypes->getTotalCount(), $typeCountAndMissingTypes->getFilledCount(), $typeCoveragePercentage, $minimalLevel ); foreach ($lines as $line) { $ruleErrors[] = RuleErrorBuilder::message($errorMessage) ->identifier($identifier) ->file($filePath) ->line($line) ->build(); } } return $ruleErrors; }
@return RuleError[] @param float|int $minimalLevel
formatErrors
php
sebastianbergmann/php-text-template
tools/.phpstan/vendor/tomasvotruba/type-coverage/src/Formatter/TypeCoverageFormatter.php
https://github.com/sebastianbergmann/php-text-template/blob/master/tools/.phpstan/vendor/tomasvotruba/type-coverage/src/Formatter/TypeCoverageFormatter.php
BSD-3-Clause
public function getReport(): Directory { if ($this->cachedReport === null) { $this->cachedReport = (new Builder($this->analyser()))->build($this); } return $this->cachedReport; }
Returns the code coverage information as a graph of node objects.
getReport
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
public function getData(bool $raw = false): ProcessedCodeCoverageData { if (!$raw) { if ($this->includeUncoveredFiles) { $this->addUncoveredFilesFromFilter(); } } return $this->data; }
Returns the collected code coverage data.
getData
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
public function append(RawCodeCoverageData $rawData, ?string $id = null, bool $append = true, ?TestStatus $status = null, null|false|TargetCollection $covers = null, ?TargetCollection $uses = null): void { if ($id === null) { $id = $this->currentId; } if ($id === null) { throw new TestIdMissingException; } if ($status === null) { $status = TestStatus::unknown(); } if ($covers === null) { $covers = TargetCollection::fromArray([]); } if ($uses === null) { $uses = TargetCollection::fromArray([]); } $size = $this->currentSize; if ($size === null) { $size = TestSize::unknown(); } $this->cachedReport = null; $this->applyFilter($rawData); $this->applyExecutableLinesFilter($rawData); if ($this->useAnnotationsForIgnoringCode) { $this->applyIgnoredLinesFilter($rawData); } $this->data->initializeUnseenData($rawData); if (!$append) { return; } if ($id === self::UNCOVERED_FILES) { return; } $linesToBeCovered = false; $linesToBeUsed = []; if ($covers !== false) { $linesToBeCovered = $this->targetMapper()->mapTargets($covers); } if ($linesToBeCovered !== false) { $linesToBeUsed = $this->targetMapper()->mapTargets($uses); } $this->applyCoversAndUsesFilter( $rawData, $linesToBeCovered, $linesToBeUsed, $size, ); if ($rawData->lineCoverage() === []) { return; } $this->tests[$id] = [ 'size' => $size->asString(), 'status' => $status->asString(), ]; $this->data->markCodeAsExecutedByTestCase($id, $rawData); }
@throws ReflectionException @throws TestIdMissingException @throws UnintentionallyCoveredCodeException
append
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
public function merge(self $that): void { $this->filter->includeFiles( $that->filter()->files(), ); $this->data->merge($that->data); $this->tests = array_merge($this->tests, $that->getTests()); $this->cachedReport = null; }
Merges the data from another instance.
merge
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
public function cachesStaticAnalysis(): bool { return $this->cacheDirectory !== null; }
@phpstan-assert-if-true !null $this->cacheDirectory
cachesStaticAnalysis
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
private function applyCoversAndUsesFilter(RawCodeCoverageData $rawData, array|false $linesToBeCovered, array $linesToBeUsed, TestSize $size): void { if ($linesToBeCovered === false) { $rawData->clear(); return; } if ($linesToBeCovered === []) { return; } if ($this->checkForUnintentionallyCoveredCode && !$size->isMedium() && !$size->isLarge()) { $this->performUnintentionallyCoveredCodeCheck($rawData, $linesToBeCovered, $linesToBeUsed); } $rawLineData = $rawData->lineCoverage(); $filesWithNoCoverage = array_diff_key($rawLineData, $linesToBeCovered); foreach (array_keys($filesWithNoCoverage) as $fileWithNoCoverage) { $rawData->removeCoverageDataForFile($fileWithNoCoverage); } foreach ($linesToBeCovered as $fileToBeCovered => $includedLines) { $rawData->keepLineCoverageDataOnlyForLines($fileToBeCovered, $includedLines); $rawData->keepFunctionCoverageDataOnlyForLines($fileToBeCovered, $includedLines); } }
@param false|TargetedLines $linesToBeCovered @param TargetedLines $linesToBeUsed @throws ReflectionException @throws UnintentionallyCoveredCodeException
applyCoversAndUsesFilter
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
private function performUnintentionallyCoveredCodeCheck(RawCodeCoverageData $data, array $linesToBeCovered, array $linesToBeUsed): void { $allowedLines = $this->getAllowedLines( $linesToBeCovered, $linesToBeUsed, ); $unintentionallyCoveredUnits = []; foreach ($data->lineCoverage() as $file => $_data) { foreach ($_data as $line => $flag) { if ($flag === 1 && !isset($allowedLines[$file][$line])) { $unintentionallyCoveredUnits[] = $this->targetMapper->lookup($file, $line); } } } $unintentionallyCoveredUnits = $this->processUnintentionallyCoveredUnits($unintentionallyCoveredUnits); if ($unintentionallyCoveredUnits !== []) { throw new UnintentionallyCoveredCodeException( $unintentionallyCoveredUnits, ); } }
@param TargetedLines $linesToBeCovered @param TargetedLines $linesToBeUsed @throws ReflectionException @throws UnintentionallyCoveredCodeException
performUnintentionallyCoveredCodeCheck
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
private function getAllowedLines(array $linesToBeCovered, array $linesToBeUsed): array { $allowedLines = []; foreach (array_keys($linesToBeCovered) as $file) { if (!isset($allowedLines[$file])) { $allowedLines[$file] = []; } $allowedLines[$file] = array_merge( $allowedLines[$file], $linesToBeCovered[$file], ); } foreach (array_keys($linesToBeUsed) as $file) { if (!isset($allowedLines[$file])) { $allowedLines[$file] = []; } $allowedLines[$file] = array_merge( $allowedLines[$file], $linesToBeUsed[$file], ); } foreach (array_keys($allowedLines) as $file) { $allowedLines[$file] = array_flip( array_unique($allowedLines[$file]), ); } return $allowedLines; }
@param TargetedLines $linesToBeCovered @param TargetedLines $linesToBeUsed @return TargetedLines
getAllowedLines
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
private function processUnintentionallyCoveredUnits(array $unintentionallyCoveredUnits): array { $unintentionallyCoveredUnits = array_unique($unintentionallyCoveredUnits); $processed = []; foreach ($unintentionallyCoveredUnits as $unintentionallyCoveredUnit) { $tmp = explode('::', $unintentionallyCoveredUnit); if (count($tmp) !== 2) { $processed[] = $unintentionallyCoveredUnit; continue; } try { $class = new ReflectionClass($tmp[0]); foreach ($this->parentClassesExcludedFromUnintentionallyCoveredCodeCheck as $parentClass) { if ($class->isSubclassOf($parentClass)) { continue 2; } } } catch (\ReflectionException $e) { throw new ReflectionException( $e->getMessage(), $e->getCode(), $e, ); } $processed[] = $tmp[0]; } $processed = array_unique($processed); sort($processed); return $processed; }
@param list<string> $unintentionallyCoveredUnits @throws ReflectionException @return list<string>
processUnintentionallyCoveredUnits
php
sebastianbergmann/php-code-coverage
src/CodeCoverage.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/CodeCoverage.php
BSD-3-Clause
private function priorityForLine(array $data, int $line): int { if (!array_key_exists($line, $data)) { return 1; } if (is_array($data[$line]) && count($data[$line]) === 0) { return 2; } if ($data[$line] === null) { return 3; } return 4; }
Determine the priority for a line. 1 = the line is not set 2 = the line has not been tested 3 = the line is dead code 4 = the line has been tested During a merge, a higher number is better. @return 1|2|3|4
priorityForLine
php
sebastianbergmann/php-code-coverage
src/Data/ProcessedCodeCoverageData.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Data/ProcessedCodeCoverageData.php
BSD-3-Clause
private function initPreviouslyUnseenFunction(string $file, string $functionName, array $functionData): void { $this->functionCoverage[$file][$functionName] = $functionData; foreach (array_keys($functionData['branches']) as $branchId) { $this->functionCoverage[$file][$functionName]['branches'][$branchId]['hit'] = []; } foreach (array_keys($functionData['paths']) as $pathId) { $this->functionCoverage[$file][$functionName]['paths'][$pathId]['hit'] = []; } }
For a function we have never seen before, copy all data over and simply init the 'hit' array. @param FunctionCoverageDataType|XdebugFunctionCoverageType $functionData
initPreviouslyUnseenFunction
php
sebastianbergmann/php-code-coverage
src/Data/ProcessedCodeCoverageData.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Data/ProcessedCodeCoverageData.php
BSD-3-Clause
private function initPreviouslySeenFunction(string $file, string $functionName, array $functionData): void { foreach ($functionData['branches'] as $branchId => $branchData) { if (!isset($this->functionCoverage[$file][$functionName]['branches'][$branchId])) { $this->functionCoverage[$file][$functionName]['branches'][$branchId] = $branchData; $this->functionCoverage[$file][$functionName]['branches'][$branchId]['hit'] = []; } } foreach ($functionData['paths'] as $pathId => $pathData) { if (!isset($this->functionCoverage[$file][$functionName]['paths'][$pathId])) { $this->functionCoverage[$file][$functionName]['paths'][$pathId] = $pathData; $this->functionCoverage[$file][$functionName]['paths'][$pathId]['hit'] = []; } } }
For a function we have seen before, only copy over and init the 'hit' array for any unseen branches and paths. Techniques such as mocking and where the contents of a file are different vary during tests (e.g. compiling containers) mean that the functions inside a file cannot be relied upon to be static. @param FunctionCoverageDataType|XdebugFunctionCoverageType $functionData
initPreviouslySeenFunction
php
sebastianbergmann/php-code-coverage
src/Data/ProcessedCodeCoverageData.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Data/ProcessedCodeCoverageData.php
BSD-3-Clause
private function __construct(array $lineCoverage, array $functionCoverage) { $this->lineCoverage = $lineCoverage; $this->functionCoverage = $functionCoverage; $this->skipEmptyLines(); }
@param XdebugCodeCoverageWithoutPathCoverageType $lineCoverage @param array<string, XdebugFunctionsCoverageType> $functionCoverage
__construct
php
sebastianbergmann/php-code-coverage
src/Data/RawCodeCoverageData.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Data/RawCodeCoverageData.php
BSD-3-Clause
private function skipEmptyLines(): void { foreach ($this->lineCoverage as $filename => $coverage) { foreach ($this->getEmptyLinesForFile($filename) as $emptyLine) { unset($this->lineCoverage[$filename][$emptyLine]); } } }
At the end of a file, the PHP interpreter always sees an implicit return. Where this occurs in a file that has e.g. a class definition, that line cannot be invoked from a test and results in confusing coverage. This engine implementation detail therefore needs to be masked which is done here by simply ensuring that all empty lines are skipped over for coverage purposes. @see https://github.com/sebastianbergmann/php-code-coverage/issues/799
skipEmptyLines
php
sebastianbergmann/php-code-coverage
src/Data/RawCodeCoverageData.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Data/RawCodeCoverageData.php
BSD-3-Clause
public function forLineCoverage(Filter $filter): Driver { $runtime = new Runtime; if ($runtime->hasPCOV()) { return new PcovDriver($filter); } if ($runtime->hasXdebug()) { return new XdebugDriver($filter); } throw new NoCodeCoverageDriverAvailableException; }
@throws NoCodeCoverageDriverAvailableException @throws PcovNotAvailableException @throws XdebugNotAvailableException @throws XdebugNotEnabledException @throws XdebugVersionNotSupportedException
forLineCoverage
php
sebastianbergmann/php-code-coverage
src/Driver/Selector.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Driver/Selector.php
BSD-3-Clause
public function forLineAndPathCoverage(Filter $filter): Driver { if ((new Runtime)->hasXdebug()) { $driver = new XdebugDriver($filter); $driver->enableBranchAndPathCoverage(); return $driver; } throw new NoCodeCoverageDriverWithPathCoverageSupportAvailableException; }
@throws NoCodeCoverageDriverWithPathCoverageSupportAvailableException @throws XdebugNotAvailableException @throws XdebugNotEnabledException @throws XdebugVersionNotSupportedException
forLineAndPathCoverage
php
sebastianbergmann/php-code-coverage
src/Driver/Selector.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Driver/Selector.php
BSD-3-Clause
public function __construct(Filter $filter) { $this->ensureXdebugIsAvailable(); if (!$filter->isEmpty()) { xdebug_set_filter( XDEBUG_FILTER_CODE_COVERAGE, XDEBUG_PATH_INCLUDE, $filter->files(), ); } }
@throws XdebugNotAvailableException @throws XdebugNotEnabledException @throws XdebugVersionNotSupportedException
__construct
php
sebastianbergmann/php-code-coverage
src/Driver/XdebugDriver.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Driver/XdebugDriver.php
BSD-3-Clause
private function ensureXdebugIsAvailable(): void { if (!extension_loaded('xdebug')) { throw new XdebugNotAvailableException; } if (!version_compare(phpversion('xdebug'), '3.1', '>=')) { throw new XdebugVersionNotSupportedException(phpversion('xdebug')); } if (!in_array('coverage', xdebug_info('mode'), true)) { throw new XdebugNotEnabledException; } }
@throws XdebugNotAvailableException @throws XdebugNotEnabledException @throws XdebugVersionNotSupportedException
ensureXdebugIsAvailable
php
sebastianbergmann/php-code-coverage
src/Driver/XdebugDriver.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Driver/XdebugDriver.php
BSD-3-Clause
private function buildDirectoryStructure(ProcessedCodeCoverageData $data): array { $result = []; foreach ($data->coveredFiles() as $originalPath) { $path = explode(DIRECTORY_SEPARATOR, $originalPath); $pointer = &$result; $max = count($path); for ($i = 0; $i < $max; $i++) { $type = ''; if ($i === ($max - 1)) { $type = '/f'; } $pointer = &$pointer[$path[$i] . $type]; } $pointer = [ 'lineCoverage' => $data->lineCoverage()[$originalPath] ?? [], 'functionCoverage' => $data->functionCoverage()[$originalPath] ?? [], ]; } return $result; }
Builds an array representation of the directory structure. For instance, <code> Array ( [Money.php] => Array ( ... ) [MoneyBag.php] => Array ( ... ) ) </code> is transformed into <code> Array ( [.] => Array ( [Money.php] => Array ( ... ) [MoneyBag.php] => Array ( ... ) ) ) </code> @return array<string, array<string, array{lineCoverage: array<int, int>, functionCoverage: array<string, array<int, int>>}>>
buildDirectoryStructure
php
sebastianbergmann/php-code-coverage
src/Node/Builder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Node/Builder.php
BSD-3-Clause
private function reducePaths(ProcessedCodeCoverageData $coverage): string { if ($coverage->coveredFiles() === []) { return '.'; } $commonPath = ''; $paths = $coverage->coveredFiles(); if (count($paths) === 1) { $commonPath = dirname($paths[0]) . DIRECTORY_SEPARATOR; $coverage->renameFile($paths[0], basename($paths[0])); return $commonPath; } $max = count($paths); for ($i = 0; $i < $max; $i++) { // strip phar:// prefixes if (str_starts_with($paths[$i], 'phar://')) { $paths[$i] = substr($paths[$i], 7); $paths[$i] = str_replace('/', DIRECTORY_SEPARATOR, $paths[$i]); } $paths[$i] = explode(DIRECTORY_SEPARATOR, $paths[$i]); if ($paths[$i][0] === '') { $paths[$i][0] = DIRECTORY_SEPARATOR; } } $done = false; $max = count($paths); while (!$done) { for ($i = 0; $i < $max - 1; $i++) { if (!isset($paths[$i][0]) || !isset($paths[$i + 1][0]) || $paths[$i][0] !== $paths[$i + 1][0]) { $done = true; break; } } if (!$done) { $commonPath .= $paths[0][0]; if ($paths[0][0] !== DIRECTORY_SEPARATOR) { $commonPath .= DIRECTORY_SEPARATOR; } for ($i = 0; $i < $max; $i++) { array_shift($paths[$i]); } } } $original = $coverage->coveredFiles(); $max = count($original); for ($i = 0; $i < $max; $i++) { $coverage->renameFile($original[$i], implode(DIRECTORY_SEPARATOR, $paths[$i])); } return substr($commonPath, 0, -1); }
Reduces the paths by cutting the longest common start path. For instance, <code> Array ( [/home/sb/Money/Money.php] => Array ( ... ) [/home/sb/Money/MoneyBag.php] => Array ( ... ) ) </code> is reduced to <code> Array ( [Money.php] => Array ( ... ) [MoneyBag.php] => Array ( ... ) ) </code>
reducePaths
php
sebastianbergmann/php-code-coverage
src/Node/Builder.php
https://github.com/sebastianbergmann/php-code-coverage/blob/master/src/Node/Builder.php
BSD-3-Clause