Supported Versions: PHP 4, PHP 5, PHP 7, PHP 8
Return all the values of an array
<?php array_values(array $array): array
<?php if ($docComment = $reflection->getDocComment()) {
$namesToCheck = [
...$namesToCheck,
...array_values(array_filter(
explode(PHP_EOL, $docComment),
fn (string $line): bool => ! str_contains($line, '* @',
))),
];
}
<?php if ($docComment = $method->getDocComment()) {
$namesToCheck = [
...$namesToCheck,
...array_values(array_filter(
explode(PHP_EOL, $docComment),
fn (string $line): bool => ! str_contains($line, '* @',
))),
];
}
}
<?php private function getConstantNames(ReflectionClass $reflection): array
{
return array_merge(...array_values((array_map(
function (ReflectionClassConstant $constant) use ($reflection): array {
foreach ($reflection->getTraits() as $trait) {
if ($trait->hasConstant($constant->getName())) {
return [];
}
}
if ($constant->class !== $reflection->name) {
return [];
}
$value = $constant->getValue();
if ($value instanceof BackedEnum) {
return is_string($value->value)
? [$value->name, $value->value]
: [$value->name];
}
return is_string($value)
? [$constant->name, $value]
: [$constant->name];
},
$reflection->getReflectionConstants()
))));
}
<?php $contentsArray = explode(PHP_EOL, $file->getContents());
$contentsArrayLines = array_map(fn ($lineNumber): int => $lineNumber + 1, array_keys($contentsArray));
$lines = array_values(array_filter(
array_map(
fn (string $line, int $lineNumber): ?int => str_contains($line, $misspellingWord) ? $lineNumber : null,
$contentsArray,
$contentsArrayLines,
),
));
if ($lines === []) {
return 0;
<?php fn (string $suggestion): bool => in_array(preg_match('/[^a-zA-Z]/', $suggestion), [0, false], true)
);
return array_slice(array_values(array_unique($suggestions)), 0, 4);
}
<?php $output = $process->getOutput();
return array_values(array_map(function (string $line): Misspelling {
[$wordMetadataAsString, $suggestionsAsString] = explode(':', trim($line));
$word = explode(' ', $wordMetadataAsString)[1];
$suggestions = explode(', ', trim($suggestionsAsString));
return new Misspelling($word, $this->takeSuggestions($suggestions));
}, array_filter(explode(PHP_EOL, $output), fn (string $line): bool => str_starts_with($line, '&'))));
}
<?php {
$path = sprintf('%s/%s.stub', self::PRESET_STUBS_DIRECTORY, $preset);
return array_values(array_filter(array_map('trim', explode("\n", (string) file_get_contents($path)))));
}