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 static function clamp(int|float $value, int|float $min, int|float $max): int|float
{
if ($min > $max) {
throw new Nette\InvalidArgumentException("Minimum ($min) is not less than maximum ($max).");
}
return min(max($value, $min), $max);
}
|
Returns value clamped to the inclusive range of min and max.
|
clamp
|
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 getSuggestion(array $possibilities, string $value): ?string
{
$best = null;
$min = (strlen($value) / 4 + 1) * 10 + .1;
foreach (array_unique($possibilities) as $item) {
if ($item !== $value && ($len = levenshtein($item, $value, 10, 11, 10)) < $min) {
$min = $len;
$best = $item;
}
}
return $best;
}
|
Looks for a string from possibilities that is most similar to value, but not the same (for 8-bit encoding).
@param string[] $possibilities
|
getSuggestion
|
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 compare(mixed $left, string $operator, mixed $right): bool
{
return match ($operator) {
'>' => $left > $right,
'>=' => $left >= $right,
'<' => $left < $right,
'<=' => $left <= $right,
'=', '==' => $left == $right,
'===' => $left === $right,
'!=', '<>' => $left != $right,
'!==' => $left !== $right,
default => throw new Nette\InvalidArgumentException("Unknown operator '$operator'"),
};
}
|
Compares two values in the same way that PHP does. Recognizes operators: >, >=, <, <=, =, ==, ===, !=, !==, <>
|
compare
|
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 el(?string $name = null, array|string|null $attrs = null): static
{
$el = new static;
$parts = explode(' ', (string) $name, 2);
$el->setName($parts[0]);
if (is_array($attrs)) {
$el->attrs = $attrs;
} elseif ($attrs !== null) {
$el->setText($attrs);
}
if (isset($parts[1])) {
foreach (Strings::matchAll($parts[1] . ' ', '#([a-z0-9:-]+)(?:=(["\'])?(.*?)(?(2)\2|\s))?#i') as $m) {
$el->attrs[$m[1]] = $m[3] ?? true;
}
}
return $el;
}
|
Constructs new HTML element.
@param array|string $attrs element's attributes or plain text content
|
el
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
public static function fromHtml(string $html): static
{
return (new static)->setHtml($html);
}
|
Returns an object representing HTML text.
|
fromHtml
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
public static function fromText(string $text): static
{
return (new static)->setText($text);
}
|
Returns an object representing plain text.
|
fromText
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
public static function htmlToText(string $html): string
{
return html_entity_decode(strip_tags($html), ENT_QUOTES | ENT_HTML5, 'UTF-8');
}
|
Converts given HTML code to plain text.
|
htmlToText
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
public function data(string $name, mixed $value = null): static
{
if (func_num_args() === 1) {
$this->attrs['data'] = $name;
} else {
$this->attrs["data-$name"] = is_bool($value)
? json_encode($value)
: $value;
}
return $this;
}
|
Setter for data-* attributes. Booleans are converted to 'true' resp. 'false'.
|
data
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
public function addText(mixed $text): static
{
if (!$text instanceof HtmlStringable) {
$text = htmlspecialchars((string) $text, ENT_NOQUOTES, 'UTF-8');
}
return $this->insert(null, $text);
}
|
Appends plain-text string to element content.
|
addText
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
final public function create(string $name, array|string|null $attrs = null): static
{
$this->insert(null, $child = static::el($name, $attrs));
return $child;
}
|
Creates and adds a new Html child.
|
create
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
final public function offsetSet($index, $child): void
{
$this->insert($index, $child, replace: true);
}
|
Inserts (replaces) child node (\ArrayAccess implementation).
@param int|null $index position or null for appending
@param Html|string $child Html node or raw HTML string
|
offsetSet
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
final public function offsetGet($index): HtmlStringable|string
{
return $this->children[$index];
}
|
Returns child node (\ArrayAccess implementation).
@param int $index
|
offsetGet
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
final public function offsetExists($index): bool
{
return isset($this->children[$index]);
}
|
Exists child node? (\ArrayAccess implementation).
@param int $index
|
offsetExists
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
public function offsetUnset($index): void
{
if (isset($this->children[$index])) {
array_splice($this->children, $index, 1);
}
}
|
Removes child node (\ArrayAccess implementation).
@param int $index
|
offsetUnset
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
final public function getIterator(): \ArrayIterator
{
return new \ArrayIterator($this->children);
}
|
Iterates over elements.
@return \ArrayIterator<int, HtmlStringable|string>
|
getIterator
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
final public function render(?int $indent = null): string
{
$s = $this->startTag();
if (!$this->isEmpty) {
// add content
if ($indent !== null) {
$indent++;
}
foreach ($this->children as $child) {
if ($child instanceof self) {
$s .= $child->render($indent);
} else {
$s .= $child;
}
}
// add end tag
$s .= $this->endTag();
}
if ($indent !== null) {
return "\n" . str_repeat("\t", $indent - 1) . $s . "\n" . str_repeat("\t", max(0, $indent - 2));
}
return $s;
}
|
Renders element's start tag, content and end tag.
|
render
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Html.php
|
BSD-3-Clause
|
public static function rgb(int $red, int $green, int $blue, int $transparency = 0): array
{
return [
'red' => max(0, min(255, $red)),
'green' => max(0, min(255, $green)),
'blue' => max(0, min(255, $blue)),
'alpha' => max(0, min(127, $transparency)),
];
}
|
Returns RGB color (0..255) and transparency (0..127).
@deprecated use ImageColor::rgb()
|
rgb
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function fromFile(string $file, ?int &$type = null): static
{
self::ensureExtension();
$type = self::detectTypeFromFile($file);
if (!$type) {
throw new UnknownImageFileException(is_file($file) ? "Unknown type of file '$file'." : "File '$file' not found.");
}
return self::invokeSafe('imagecreatefrom' . self::Formats[$type], $file, "Unable to open file '$file'.", __METHOD__);
}
|
Reads an image from a file and returns its type in $type.
@throws Nette\NotSupportedException if gd extension is not loaded
@throws UnknownImageFileException if file not found or file type is not known
|
fromFile
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function fromString(string $s, ?int &$type = null): static
{
self::ensureExtension();
$type = self::detectTypeFromString($s);
if (!$type) {
throw new UnknownImageFileException('Unknown type of image.');
}
return self::invokeSafe('imagecreatefromstring', $s, 'Unable to open image from string.', __METHOD__);
}
|
Reads an image from a string and returns its type in $type.
@throws Nette\NotSupportedException if gd extension is not loaded
@throws ImageException
|
fromString
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function fromBlank(int $width, int $height, ImageColor|array|null $color = null): static
{
self::ensureExtension();
if ($width < 1 || $height < 1) {
throw new Nette\InvalidArgumentException('Image width and height must be greater than zero.');
}
$image = new static(imagecreatetruecolor($width, $height));
if ($color) {
$image->alphablending(false);
$image->filledrectangle(0, 0, $width - 1, $height - 1, $color);
$image->alphablending(true);
}
return $image;
}
|
Creates a new true color image of the given dimensions. The default color is black.
@param positive-int $width
@param positive-int $height
@throws Nette\NotSupportedException if gd extension is not loaded
|
fromBlank
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function detectTypeFromFile(string $file, &$width = null, &$height = null): ?int
{
[$width, $height, $type] = @getimagesize($file); // @ - files smaller than 12 bytes causes read error
return isset(self::Formats[$type]) ? $type : null;
}
|
Returns the type of image from file.
@return ImageType::*|null
|
detectTypeFromFile
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function detectTypeFromString(string $s, &$width = null, &$height = null): ?int
{
[$width, $height, $type] = @getimagesizefromstring($s); // @ - strings smaller than 12 bytes causes read error
return isset(self::Formats[$type]) ? $type : null;
}
|
Returns the type of image from string.
@return ImageType::*|null
|
detectTypeFromString
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function typeToExtension(int $type): string
{
if (!isset(self::Formats[$type])) {
throw new Nette\InvalidArgumentException("Unsupported image type '$type'.");
}
return self::Formats[$type];
}
|
Returns the file extension for the given image type.
@param ImageType::* $type
@return value-of<self::Formats>
|
typeToExtension
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function extensionToType(string $extension): int
{
$extensions = array_flip(self::Formats) + ['jpg' => ImageType::JPEG];
$extension = strtolower($extension);
if (!isset($extensions[$extension])) {
throw new Nette\InvalidArgumentException("Unsupported file extension '$extension'.");
}
return $extensions[$extension];
}
|
Returns the image type for given file extension.
@return ImageType::*
|
extensionToType
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function typeToMimeType(int $type): string
{
return 'image/' . self::typeToExtension($type);
}
|
Returns the mime type for the given image type.
@param ImageType::* $type
|
typeToMimeType
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function getWidth(): int
{
return imagesx($this->image);
}
|
Returns image width.
@return positive-int
|
getWidth
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function getHeight(): int
{
return imagesy($this->image);
}
|
Returns image height.
@return positive-int
|
getHeight
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function resize(int|string|null $width, int|string|null $height, int $mode = self::OrSmaller): static
{
if ($mode & self::Cover) {
return $this->resize($width, $height, self::OrBigger)->crop('50%', '50%', $width, $height);
}
[$newWidth, $newHeight] = static::calculateSize($this->getWidth(), $this->getHeight(), $width, $height, $mode);
if ($newWidth !== $this->getWidth() || $newHeight !== $this->getHeight()) { // resize
$newImage = static::fromBlank($newWidth, $newHeight, ImageColor::rgb(0, 0, 0, 0))->getImageResource();
imagecopyresampled(
$newImage,
$this->image,
0,
0,
0,
0,
$newWidth,
$newHeight,
$this->getWidth(),
$this->getHeight(),
);
$this->image = $newImage;
}
if ($width < 0 || $height < 0) {
imageflip($this->image, $width < 0 ? ($height < 0 ? IMG_FLIP_BOTH : IMG_FLIP_HORIZONTAL) : IMG_FLIP_VERTICAL);
}
return $this;
}
|
Scales an image. Width and height accept pixels or percent.
@param int-mask-of<self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
|
resize
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function calculateSize(
int $srcWidth,
int $srcHeight,
$newWidth,
$newHeight,
int $mode = self::OrSmaller,
): array
{
if ($newWidth === null) {
} elseif (self::isPercent($newWidth)) {
$newWidth = (int) round($srcWidth / 100 * abs($newWidth));
$percents = true;
} else {
$newWidth = abs($newWidth);
}
if ($newHeight === null) {
} elseif (self::isPercent($newHeight)) {
$newHeight = (int) round($srcHeight / 100 * abs($newHeight));
$mode |= empty($percents) ? 0 : self::Stretch;
} else {
$newHeight = abs($newHeight);
}
if ($mode & self::Stretch) { // non-proportional
if (!$newWidth || !$newHeight) {
throw new Nette\InvalidArgumentException('For stretching must be both width and height specified.');
}
if ($mode & self::ShrinkOnly) {
$newWidth = min($srcWidth, $newWidth);
$newHeight = min($srcHeight, $newHeight);
}
} else { // proportional
if (!$newWidth && !$newHeight) {
throw new Nette\InvalidArgumentException('At least width or height must be specified.');
}
$scale = [];
if ($newWidth > 0) { // fit width
$scale[] = $newWidth / $srcWidth;
}
if ($newHeight > 0) { // fit height
$scale[] = $newHeight / $srcHeight;
}
if ($mode & self::OrBigger) {
$scale = [max($scale)];
}
if ($mode & self::ShrinkOnly) {
$scale[] = 1;
}
$scale = min($scale);
$newWidth = (int) round($srcWidth * $scale);
$newHeight = (int) round($srcHeight * $scale);
}
return [max($newWidth, 1), max($newHeight, 1)];
}
|
Calculates dimensions of resized image. Width and height accept pixels or percent.
@param int-mask-of<self::OrSmaller|self::OrBigger|self::Stretch|self::Cover|self::ShrinkOnly> $mode
|
calculateSize
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function crop(int|string $left, int|string $top, int|string $width, int|string $height): static
{
[$r['x'], $r['y'], $r['width'], $r['height']]
= static::calculateCutout($this->getWidth(), $this->getHeight(), $left, $top, $width, $height);
if (gd_info()['GD Version'] === 'bundled (2.1.0 compatible)') {
$this->image = imagecrop($this->image, $r);
imagesavealpha($this->image, true);
} else {
$newImage = static::fromBlank($r['width'], $r['height'], ImageColor::rgb(0, 0, 0, 0))->getImageResource();
imagecopy($newImage, $this->image, 0, 0, $r['x'], $r['y'], $r['width'], $r['height']);
$this->image = $newImage;
}
return $this;
}
|
Crops image. Arguments accepts pixels or percent.
|
crop
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function calculateCutout(
int $srcWidth,
int $srcHeight,
int|string $left,
int|string $top,
int|string $newWidth,
int|string $newHeight,
): array
{
if (self::isPercent($newWidth)) {
$newWidth = (int) round($srcWidth / 100 * $newWidth);
}
if (self::isPercent($newHeight)) {
$newHeight = (int) round($srcHeight / 100 * $newHeight);
}
if (self::isPercent($left)) {
$left = (int) round(($srcWidth - $newWidth) / 100 * $left);
}
if (self::isPercent($top)) {
$top = (int) round(($srcHeight - $newHeight) / 100 * $top);
}
if ($left < 0) {
$newWidth += $left;
$left = 0;
}
if ($top < 0) {
$newHeight += $top;
$top = 0;
}
$newWidth = min($newWidth, $srcWidth - $left);
$newHeight = min($newHeight, $srcHeight - $top);
return [$left, $top, $newWidth, $newHeight];
}
|
Calculates dimensions of cutout in image. Arguments accepts pixels or percent.
|
calculateCutout
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function place(self $image, int|string $left = 0, int|string $top = 0, int $opacity = 100): static
{
$opacity = max(0, min(100, $opacity));
if ($opacity === 0) {
return $this;
}
$width = $image->getWidth();
$height = $image->getHeight();
if (self::isPercent($left)) {
$left = (int) round(($this->getWidth() - $width) / 100 * $left);
}
if (self::isPercent($top)) {
$top = (int) round(($this->getHeight() - $height) / 100 * $top);
}
$output = $input = $image->image;
if ($opacity < 100) {
$tbl = [];
for ($i = 0; $i < 128; $i++) {
$tbl[$i] = round(127 - (127 - $i) * $opacity / 100);
}
$output = imagecreatetruecolor($width, $height);
imagealphablending($output, false);
if (!$image->isTrueColor()) {
$input = $output;
imagefilledrectangle($output, 0, 0, $width, $height, imagecolorallocatealpha($output, 0, 0, 0, 127));
imagecopy($output, $image->image, 0, 0, 0, 0, $width, $height);
}
for ($x = 0; $x < $width; $x++) {
for ($y = 0; $y < $height; $y++) {
$c = \imagecolorat($input, $x, $y);
$c = ($c & 0xFFFFFF) + ($tbl[$c >> 24] << 24);
\imagesetpixel($output, $x, $y, $c);
}
}
imagealphablending($output, true);
}
imagecopy(
$this->image,
$output,
$left,
$top,
0,
0,
$width,
$height,
);
return $this;
}
|
Puts another image into this image. Left and top accepts pixels or percent.
@param int<0, 100> $opacity 0..100
|
place
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function calculateTextBox(
string $text,
string $fontFile,
float $size,
float $angle = 0,
array $options = [],
): array
{
self::ensureExtension();
$box = imagettfbbox($size, $angle, $fontFile, $text, $options);
return [
'left' => $minX = min([$box[0], $box[2], $box[4], $box[6]]),
'top' => $minY = min([$box[1], $box[3], $box[5], $box[7]]),
'width' => max([$box[0], $box[2], $box[4], $box[6]]) - $minX + 1,
'height' => max([$box[1], $box[3], $box[5], $box[7]]) - $minY + 1,
];
}
|
Calculates the bounding box for a TrueType text. Returns keys left, top, width and height.
|
calculateTextBox
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function save(string $file, ?int $quality = null, ?int $type = null): void
{
$type ??= self::extensionToType(pathinfo($file, PATHINFO_EXTENSION));
$this->output($type, $quality, $file);
}
|
Saves image to the file. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
@param ImageType::*|null $type
@throws ImageException
|
save
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function toString(int $type = ImageType::JPEG, ?int $quality = null): string
{
return Helpers::capture(function () use ($type, $quality): void {
$this->output($type, $quality);
});
}
|
Outputs image to string. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
@param ImageType::* $type
|
toString
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function send(int $type = ImageType::JPEG, ?int $quality = null): void
{
header('Content-Type: ' . self::typeToMimeType($type));
$this->output($type, $quality);
}
|
Outputs image to browser. Quality is in the range 0..100 for JPEG (default 85), WEBP (default 80) and AVIF (default 30) and 0..9 for PNG (default 9).
@param ImageType::* $type
@throws ImageException
|
send
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
private function output(int $type, ?int $quality, ?string $file = null): void
{
[$defQuality, $min, $max] = match ($type) {
ImageType::JPEG => [85, 0, 100],
ImageType::PNG => [9, 0, 9],
ImageType::GIF => [null, null, null],
ImageType::WEBP => [80, 0, 100],
ImageType::AVIF => [30, 0, 100],
ImageType::BMP => [null, null, null],
default => throw new Nette\InvalidArgumentException("Unsupported image type '$type'."),
};
$args = [$this->image, $file];
if ($defQuality !== null) {
$args[] = $quality === null ? $defQuality : max($min, min($max, $quality));
}
Callback::invokeSafe('image' . self::Formats[$type], $args, function (string $message) use ($file): void {
if ($file !== null) {
@unlink($file);
}
throw new ImageException($message);
});
}
|
Outputs image to browser or file.
@param ImageType::* $type
@throws ImageException
|
output
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public function __call(string $name, array $args): mixed
{
$function = 'image' . $name;
if (!function_exists($function)) {
ObjectHelpers::strictCall(static::class, $name);
}
foreach ($args as $key => $value) {
if ($value instanceof self) {
$args[$key] = $value->getImageResource();
} elseif ($value instanceof ImageColor || (is_array($value) && isset($value['red']))) {
$args[$key] = $this->resolveColor($value);
}
}
$res = $function($this->image, ...$args);
return $res instanceof \GdImage
? $this->setImageResource($res)
: $res;
}
|
Call to undefined method.
@throws Nette\MemberAccessException
|
__call
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Image.php
|
BSD-3-Clause
|
public static function hex(string $hex): self
{
$hex = ltrim($hex, '#');
$len = strlen($hex);
if ($len === 3 || $len === 4) {
return new self(
(int) hexdec($hex[0]) * 17,
(int) hexdec($hex[1]) * 17,
(int) hexdec($hex[2]) * 17,
(int) hexdec($hex[3] ?? 'F') * 17 / 255,
);
} elseif ($len === 6 || $len === 8) {
return new self(
(int) hexdec($hex[0] . $hex[1]),
(int) hexdec($hex[2] . $hex[3]),
(int) hexdec($hex[4] . $hex[5]),
(int) hexdec(($hex[6] ?? 'F') . ($hex[7] ?? 'F')) / 255,
);
} else {
throw new Nette\InvalidArgumentException('Invalid hex color format.');
}
}
|
Accepts formats #RRGGBB, #RRGGBBAA, #RGB, #RGBA
|
hex
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/ImageColor.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ImageColor.php
|
BSD-3-Clause
|
public static function contains(iterable $iterable, mixed $value): bool
{
foreach ($iterable as $v) {
if ($v === $value) {
return true;
}
}
return false;
}
|
Tests for the presence of value.
|
contains
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function containsKey(iterable $iterable, mixed $key): bool
{
foreach ($iterable as $k => $v) {
if ($k === $key) {
return true;
}
}
return false;
}
|
Tests for the presence of key.
|
containsKey
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function first(iterable $iterable, ?callable $predicate = null, ?callable $else = null): mixed
{
foreach ($iterable as $k => $v) {
if (!$predicate || $predicate($v, $k, $iterable)) {
return $v;
}
}
return $else ? $else() : null;
}
|
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
@template V
@param iterable<K, V> $iterable
@param ?callable(V, K, iterable<K, V>): bool $predicate
@return ?V
|
first
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function firstKey(iterable $iterable, ?callable $predicate = null, ?callable $else = null): mixed
{
foreach ($iterable as $k => $v) {
if (!$predicate || $predicate($v, $k, $iterable)) {
return $k;
}
}
return $else ? $else() : null;
}
|
Returns the key of first item (matching the specified predicate if given). If there is no such item, it returns result of invoking $else or null.
@template K
@template V
@param iterable<K, V> $iterable
@param ?callable(V, K, iterable<K, V>): bool $predicate
@return ?K
|
firstKey
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function some(iterable $iterable, callable $predicate): bool
{
foreach ($iterable as $k => $v) {
if ($predicate($v, $k, $iterable)) {
return true;
}
}
return false;
}
|
Tests whether at least one element in the iterator passes the test implemented by the provided function.
@template K
@template V
@param iterable<K, V> $iterable
@param callable(V, K, iterable<K, V>): bool $predicate
|
some
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function every(iterable $iterable, callable $predicate): bool
{
foreach ($iterable as $k => $v) {
if (!$predicate($v, $k, $iterable)) {
return false;
}
}
return true;
}
|
Tests whether all elements in the iterator pass the test implemented by the provided function.
@template K
@template V
@param iterable<K, V> $iterable
@param callable(V, K, iterable<K, V>): bool $predicate
|
every
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function filter(iterable $iterable, callable $predicate): \Generator
{
foreach ($iterable as $k => $v) {
if ($predicate($v, $k, $iterable)) {
yield $k => $v;
}
}
}
|
Iterator that filters elements according to a given $predicate. Maintains original keys.
@template K
@template V
@param iterable<K, V> $iterable
@param callable(V, K, iterable<K, V>): bool $predicate
@return \Generator<K, V>
|
filter
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function map(iterable $iterable, callable $transformer): \Generator
{
foreach ($iterable as $k => $v) {
yield $k => $transformer($v, $k, $iterable);
}
}
|
Iterator that transforms values by calling $transformer. Maintains original keys.
@template K
@template V
@template R
@param iterable<K, V> $iterable
@param callable(V, K, iterable<K, V>): R $transformer
@return \Generator<K, R>
|
map
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function mapWithKeys(iterable $iterable, callable $transformer): \Generator
{
foreach ($iterable as $k => $v) {
$pair = $transformer($v, $k, $iterable);
if ($pair) {
yield $pair[0] => $pair[1];
}
}
}
|
Iterator that transforms keys and values by calling $transformer. If it returns null, the element is skipped.
@template K
@template V
@template ResV
@template ResK
@param iterable<K, V> $iterable
@param callable(V, K, iterable<K, V>): ?array{ResV, ResK} $transformer
@return \Generator<ResV, ResK>
|
mapWithKeys
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function memoize(iterable $iterable): iterable
{
return new class (self::toIterator($iterable)) implements \IteratorAggregate {
public function __construct(
private \Iterator $iterator,
private array $cache = [],
) {
}
public function getIterator(): \Generator
{
if (!$this->cache) {
$this->iterator->rewind();
}
$i = 0;
while (true) {
if (isset($this->cache[$i])) {
[$k, $v] = $this->cache[$i];
} elseif ($this->iterator->valid()) {
$k = $this->iterator->key();
$v = $this->iterator->current();
$this->iterator->next();
$this->cache[$i] = [$k, $v];
} else {
break;
}
yield $k => $v;
$i++;
}
}
};
}
|
Wraps around iterator and caches its keys and values during iteration.
This allows the data to be re-iterated multiple times.
@template K
@template V
@param iterable<K, V> $iterable
@return \IteratorAggregate<K, V>
|
memoize
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function toIterator(iterable $iterable): \Iterator
{
return match (true) {
$iterable instanceof \Iterator => $iterable,
$iterable instanceof \IteratorAggregate => self::toIterator($iterable->getIterator()),
is_array($iterable) => new \ArrayIterator($iterable),
default => throw new Nette\ShouldNotHappenException,
};
}
|
Creates an iterator from anything that is iterable.
@template K
@template V
@param iterable<K, V> $iterable
@return \Iterator<K, V>
|
toIterator
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Iterables.php
|
BSD-3-Clause
|
public static function encode(
mixed $value,
bool|int $pretty = false,
bool $asciiSafe = false,
bool $htmlSafe = false,
bool $forceObjects = false,
): string
{
if (is_int($pretty)) { // back compatibility
$flags = ($pretty & self::ESCAPE_UNICODE ? 0 : JSON_UNESCAPED_UNICODE) | ($pretty & ~self::ESCAPE_UNICODE);
} else {
$flags = ($asciiSafe ? 0 : JSON_UNESCAPED_UNICODE)
| ($pretty ? JSON_PRETTY_PRINT : 0)
| ($forceObjects ? JSON_FORCE_OBJECT : 0)
| ($htmlSafe ? JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT | JSON_HEX_TAG : 0);
}
$flags |= JSON_UNESCAPED_SLASHES
| (defined('JSON_PRESERVE_ZERO_FRACTION') ? JSON_PRESERVE_ZERO_FRACTION : 0); // since PHP 5.6.6 & PECL JSON-C 1.3.7
$json = json_encode($value, $flags);
if ($error = json_last_error()) {
throw new JsonException(json_last_error_msg(), $error);
}
return $json;
}
|
Converts value to JSON format. Use $pretty for easier reading and clarity, $asciiSafe for ASCII output
and $htmlSafe for HTML escaping, $forceObjects enforces the encoding of non-associateve arrays as objects.
@throws JsonException
|
encode
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
|
BSD-3-Clause
|
public static function decode(string $json, bool|int $forceArrays = false): mixed
{
$flags = is_int($forceArrays) // back compatibility
? $forceArrays
: ($forceArrays ? JSON_OBJECT_AS_ARRAY : 0);
$flags |= JSON_BIGINT_AS_STRING;
$value = json_decode($json, flags: $flags);
if ($error = json_last_error()) {
throw new JsonException(json_last_error_msg(), $error);
}
return $value;
}
|
Parses JSON to PHP value. The $forceArrays enforces the decoding of objects as arrays.
@throws JsonException
|
decode
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Json.php
|
BSD-3-Clause
|
public static function getMagicProperties(string $class): array
{
static $cache;
$props = &$cache[$class];
if ($props !== null) {
return $props;
}
$rc = new \ReflectionClass($class);
preg_match_all(
'~^ [ \t*]* @property(|-read|-write|-deprecated) [ \t]+ [^\s$]+ [ \t]+ \$ (\w+) ()~mx',
(string) $rc->getDocComment(),
$matches,
PREG_SET_ORDER,
);
$props = [];
foreach ($matches as [, $type, $name]) {
$uname = ucfirst($name);
$write = $type !== '-read'
&& $rc->hasMethod($nm = 'set' . $uname)
&& ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
$read = $type !== '-write'
&& ($rc->hasMethod($nm = 'get' . $uname) || $rc->hasMethod($nm = 'is' . $uname))
&& ($rm = $rc->getMethod($nm))->name === $nm && !$rm->isPrivate() && !$rm->isStatic();
if ($read || $write) {
$props[$name] = $read << 0 | ($nm[0] === 'g') << 1 | $rm->returnsReference() << 2 | $write << 3 | ($type === '-deprecated') << 4;
}
}
foreach ($rc->getTraits() as $trait) {
$props += self::getMagicProperties($trait->name);
}
if ($parent = get_parent_class($class)) {
$props += self::getMagicProperties($parent);
}
return $props;
}
|
Returns array of magic properties defined by annotation @property.
@return array of [name => bit mask]
@internal
|
getMagicProperties
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
|
BSD-3-Clause
|
public static function getSuggestion(array $possibilities, string $value): ?string
{
$norm = preg_replace($re = '#^(get|set|has|is|add)(?=[A-Z])#', '+', $value);
$best = null;
$min = (strlen($value) / 4 + 1) * 10 + .1;
foreach (array_unique($possibilities, SORT_REGULAR) as $item) {
$item = $item instanceof \Reflector ? $item->name : $item;
if ($item !== $value && (
($len = levenshtein($item, $value, 10, 11, 10)) < $min
|| ($len = levenshtein(preg_replace($re, '*', $item), $norm, 10, 11, 10)) < $min
)) {
$min = $len;
$best = $item;
}
}
return $best;
}
|
Finds the best suggestion (for 8-bit encoding).
@param (\ReflectionFunctionAbstract|\ReflectionParameter|\ReflectionClass|\ReflectionProperty|string)[] $possibilities
@internal
|
getSuggestion
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
|
BSD-3-Clause
|
public static function hasProperty(string $class, string $name): bool|string
{
static $cache;
$prop = &$cache[$class][$name];
if ($prop === null) {
$prop = false;
try {
$rp = new \ReflectionProperty($class, $name);
if ($rp->isPublic() && !$rp->isStatic()) {
$prop = $name >= 'onA' && $name < 'on_' ? 'event' : true;
}
} catch (\ReflectionException $e) {
}
}
return $prop;
}
|
Checks if the public non-static property exists.
Returns 'event' if the property exists and has event like name
@internal
|
hasProperty
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/ObjectHelpers.php
|
BSD-3-Clause
|
public function getFirstItemOnPage(): int
{
return $this->itemCount !== 0
? $this->offset + 1
: 0;
}
|
Returns the sequence number of the first element on the page
@return int<0, max>
|
getFirstItemOnPage
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function getLastItemOnPage(): int
{
return $this->offset + $this->length;
}
|
Returns the sequence number of the last element on the page
@return int<0, max>
|
getLastItemOnPage
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
protected function getPageIndex(): int
{
$index = max(0, $this->page - $this->base);
return $this->itemCount === null
? $index
: min($index, max(0, $this->getPageCount() - 1));
}
|
Returns zero-based page number.
@return int<0, max>
|
getPageIndex
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function isFirst(): bool
{
return $this->getPageIndex() === 0;
}
|
Is the current page the first one?
|
isFirst
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function isLast(): bool
{
return $this->itemCount === null
? false
: $this->getPageIndex() >= $this->getPageCount() - 1;
}
|
Is the current page the last one?
|
isLast
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function getPageCount(): ?int
{
return $this->itemCount === null
? null
: (int) ceil($this->itemCount / $this->itemsPerPage);
}
|
Returns the total number of pages.
@return int<0, max>|null
|
getPageCount
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function setItemsPerPage(int $itemsPerPage): static
{
$this->itemsPerPage = max(1, $itemsPerPage);
return $this;
}
|
Sets the number of items to display on a single page.
|
setItemsPerPage
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function getItemsPerPage(): int
{
return $this->itemsPerPage;
}
|
Returns the number of items to display on a single page.
@return positive-int
|
getItemsPerPage
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function setItemCount(?int $itemCount = null): static
{
$this->itemCount = $itemCount === null ? null : max(0, $itemCount);
return $this;
}
|
Sets the total number of items.
|
setItemCount
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
BSD-3-Clause
|
public function getItemCount(): ?int
{
return $this->itemCount;
}
|
Returns the total number of items.
@return int<0, max>|null
|
getItemCount
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Paginator.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Random.php
|
https://github.com/sebastianbergmann/php-code-coverage/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\Validators::isBuiltinType()
|
isBuiltinType
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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\Validators::isClassKeyword()
|
isClassKeyword
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Reflection.php
|
https://github.com/sebastianbergmann/php-code-coverage/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\Validators::isUnicode()
|
checkEncoding
|
php
|
sebastianbergmann/php-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/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-code-coverage
|
tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
https://github.com/sebastianbergmann/php-code-coverage/blob/master/tools/.phpstan/vendor/nette/utils/src/Utils/Strings.php
|
BSD-3-Clause
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.