Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete: During the deletion of a folder, additional files may be added. #279

Open
wants to merge 24 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
coding style
dg committed Jan 28, 2022
commit 3f971c0427323535c13c06ba97dc55d97ecc87c1
2 changes: 1 addition & 1 deletion src/Iterators/CachingIterator.php
Original file line number Diff line number Diff line change
@@ -48,7 +48,7 @@ public function __construct($iterator)
} elseif ($iterator instanceof \Traversable) {
$iterator = new \IteratorIterator($iterator);
} else {
throw new Nette\InvalidArgumentException(sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', self::class, is_object($iterator) ? get_class($iterator) : gettype($iterator)));
throw new Nette\InvalidArgumentException(sprintf('Invalid argument passed to %s; array or Traversable expected, %s given.', self::class, is_object($iterator) ? $iterator::class : gettype($iterator)));
}

parent::__construct($iterator, 0);
2 changes: 1 addition & 1 deletion src/Utils/Callback.php
Original file line number Diff line number Diff line change
@@ -61,7 +61,7 @@ public static function check($callable, bool $syntax = false)
throw new Nette\InvalidArgumentException(
$syntax
? 'Given value is not a callable type.'
: sprintf("Callback '%s' is not callable.", self::toString($callable))
: sprintf("Callback '%s' is not callable.", self::toString($callable)),
);
}

6 changes: 3 additions & 3 deletions src/Utils/DateTime.php
Original file line number Diff line number Diff line change
@@ -32,10 +32,10 @@ class DateTime extends \DateTime implements \JsonSerializable
public const WEEK = 7 * self::DAY;

/** average month in seconds */
public const MONTH = 2629800;
public const MONTH = 2_629_800;

/** average year in seconds */
public const YEAR = 31557600;
public const YEAR = 31_557_600;


/**
@@ -73,7 +73,7 @@ public static function fromParts(
int $day,
int $hour = 0,
int $minute = 0,
float $second = 0.0
float $second = 0.0,
) {
$s = sprintf('%04d-%02d-%02d %02d:%02d:%02.5F', $year, $month, $day, $hour, $minute, $second);
if (
20 changes: 10 additions & 10 deletions src/Utils/FileSystem.php
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ public static function createDir(string $dir, int $mode = 0777): void
"Unable to create directory '%s' with mode %s. %s",
self::normalizePath($dir),
decoct($mode),
Helpers::getLastError()
Helpers::getLastError(),
));
}
}
@@ -73,7 +73,7 @@ public static function copy(string $origin, string $target, bool $overwrite = tr
"Unable to copy file '%s' to '%s'. %s",
self::normalizePath($origin),
self::normalizePath($target),
Helpers::getLastError()
Helpers::getLastError(),
));
}
}
@@ -92,7 +92,7 @@ public static function delete(string $path): void
throw new Nette\IOException(sprintf(
"Unable to delete '%s'. %s",
self::normalizePath($path),
Helpers::getLastError()
Helpers::getLastError(),
));
}
} elseif (is_dir($path)) {
@@ -104,7 +104,7 @@ public static function delete(string $path): void
throw new Nette\IOException(sprintf(
"Unable to delete directory '%s'. %s",
self::normalizePath($path),
Helpers::getLastError()
Helpers::getLastError(),
));
}
}
@@ -135,7 +135,7 @@ public static function rename(string $origin, string $target, bool $overwrite =
"Unable to rename file or directory '%s' to '%s'. %s",
self::normalizePath($origin),
self::normalizePath($target),
Helpers::getLastError()
Helpers::getLastError(),
));
}
}
@@ -153,7 +153,7 @@ public static function read(string $file): string
throw new Nette\IOException(sprintf(
"Unable to read file '%s'. %s",
self::normalizePath($file),
Helpers::getLastError()
Helpers::getLastError(),
));
}

@@ -172,7 +172,7 @@ public static function write(string $file, string $content, ?int $mode = 0666):
throw new Nette\IOException(sprintf(
"Unable to write file '%s'. %s",
self::normalizePath($file),
Helpers::getLastError()
Helpers::getLastError(),
));
}

@@ -181,7 +181,7 @@ public static function write(string $file, string $content, ?int $mode = 0666):
"Unable to chmod file '%s' to mode %s. %s",
self::normalizePath($file),
decoct($mode),
Helpers::getLastError()
Helpers::getLastError(),
));
}
}
@@ -199,7 +199,7 @@ public static function makeWritable(string $path, int $dirMode = 0777, int $file
"Unable to chmod file '%s' to mode %s. %s",
self::normalizePath($path),
decoct($fileMode),
Helpers::getLastError()
Helpers::getLastError(),
));
}
} elseif (is_dir($path)) {
@@ -212,7 +212,7 @@ public static function makeWritable(string $path, int $dirMode = 0777, int $file
"Unable to chmod directory '%s' to mode %s. %s",
self::normalizePath($path),
decoct($dirMode),
Helpers::getLastError()
Helpers::getLastError(),
));
}
} else {
2 changes: 1 addition & 1 deletion src/Utils/Html.php
Original file line number Diff line number Diff line change
@@ -853,7 +853,7 @@ final public function attributes(): string
. str_replace(
['&', $q, '<'],
['&amp;', $q === '"' ? '&quot;' : '&#39;', self::$xhtml ? '&lt;' : '<'],
$value
$value,
)
. (strpos($value, '`') !== false && strpbrk($value, ' <>"\'') === false ? ' ' : '')
. $q;
12 changes: 6 additions & 6 deletions src/Utils/Image.php
Original file line number Diff line number Diff line change
@@ -354,7 +354,7 @@ public function resize($width, $height, int $flags = self::FIT)
$newWidth,
$newHeight,
$this->getWidth(),
$this->getHeight()
$this->getHeight(),
);
$this->image = $newImage;
}
@@ -377,7 +377,7 @@ public static function calculateSize(
int $srcHeight,
$newWidth,
$newHeight,
int $flags = self::FIT
int $flags = self::FIT,
): array {
if ($newWidth === null) {
} elseif (self::isPercent($newWidth)) {
@@ -575,7 +575,7 @@ public function place(self $image, $left = 0, $top = 0, int $opacity = 100)
0,
0,
$width,
$height
$height,
);
return $this;
}
@@ -606,7 +606,7 @@ public function save(string $file, ?int $quality = null, ?int $type = null): voi
*/
public function toString(int $type = self::JPEG, ?int $quality = null): string
{
return Helpers::capture(function () use ($type, $quality) {
return Helpers::capture(function () use ($type, $quality): void {
$this->output($type, $quality);
});
}
@@ -699,13 +699,13 @@ public function __call(string $name, array $args)
$value['red'],
$value['green'],
$value['blue'],
$value['alpha']
$value['alpha'],
) ?: imagecolorresolvealpha(
$this->image,
$value['red'],
$value['green'],
$value['blue'],
$value['alpha']
$value['alpha'],
);
}
}
18 changes: 9 additions & 9 deletions src/Utils/ObjectHelpers.php
Original file line number Diff line number Diff line change
@@ -28,8 +28,8 @@ public static function strictGet(string $class, string $name): void
{
$rc = new \ReflectionClass($class);
$hint = self::getSuggestion(array_merge(
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-read)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
), $name);
throw new MemberAccessException("Cannot read an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
}
@@ -43,8 +43,8 @@ public static function strictSet(string $class, string $name): void
{
$rc = new \ReflectionClass($class);
$hint = self::getSuggestion(array_merge(
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), function ($p) { return !$p->isStatic(); }),
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m')
array_filter($rc->getProperties(\ReflectionProperty::IS_PUBLIC), fn($p) => !$p->isStatic()),
self::parseFullDoc($rc, '~^[ \t*]*@property(?:-write)?[ \t]+(?:\S+[ \t]+)??\$(\w+)~m'),
), $name);
throw new MemberAccessException("Cannot write to an undeclared property $class::\$$name" . ($hint ? ", did you mean \$$hint?" : '.'));
}
@@ -76,7 +76,7 @@ public static function strictCall(string $class, string $method, array $addition
$hint = self::getSuggestion(array_merge(
get_class_methods($class),
self::parseFullDoc(new \ReflectionClass($class), '~^[ \t*]*@method[ \t]+(?:static[ \t]+)?(?:\S+[ \t]+)??(\w+)\(~m'),
$additionalMethods
$additionalMethods,
), $method);
throw new MemberAccessException("Call to undefined method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
}
@@ -107,8 +107,8 @@ public static function strictStaticCall(string $class, string $method): void

} else {
$hint = self::getSuggestion(
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), function ($m) { return $m->isStatic(); }),
$method
array_filter((new \ReflectionClass($class))->getMethods(\ReflectionMethod::IS_PUBLIC), fn($m) => $m->isStatic()),
$method,
);
throw new MemberAccessException("Call to undefined static method $class::$method()" . ($hint ? ", did you mean $hint()?" : '.'));
}
@@ -133,7 +133,7 @@ public static function getMagicProperties(string $class): array
'~^ [ \t*]* @property(|-read|-write|-deprecated) [ \t]+ [^\s$]+ [ \t]+ \$ (\w+) ()~mx',
(string) $rc->getDocComment(),
$matches,
PREG_SET_ORDER
PREG_SET_ORDER,
);

$props = [];
@@ -199,7 +199,7 @@ private static function parseFullDoc(\ReflectionClass $rc, string $pattern): arr
}
} while ($rc = $rc->getParentClass());

return preg_match_all($pattern, implode($doc), $m) ? $m[1] : [];
return preg_match_all($pattern, implode('', $doc), $m) ? $m[1] : [];
}


9 changes: 6 additions & 3 deletions src/Utils/Random.php
Original file line number Diff line number Diff line change
@@ -25,9 +25,12 @@ final class Random
*/
public static function generate(int $length = 10, string $charlist = '0-9a-z'): string
{
$charlist = count_chars(preg_replace_callback('#.-.#', function (array $m): string {
return implode('', range($m[0][0], $m[0][2]));
}, $charlist), 3);
$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) {
2 changes: 1 addition & 1 deletion src/Utils/Strings.php
Original file line number Diff line number Diff line change
@@ -186,7 +186,7 @@ public static function toAscii(string $s): string
$s = strtr(
$s,
"\xa5\xa3\xbc\x8c\xa7\x8a\xaa\x8d\x8f\x8e\xaf\xb9\xb3\xbe\x9c\x9a\xba\x9d\x9f\x9e\xbf\xc0\xc1\xc2\xc3\xc4\xc5\xc6\xc7\xc8\xc9\xca\xcb\xcc\xcd\xce\xcf\xd0\xd1\xd2\xd3\xd4\xd5\xd6\xd7\xd8\xd9\xda\xdb\xdc\xdd\xde\xdf\xe0\xe1\xe2\xe3\xe4\xe5\xe6\xe7\xe8\xe9\xea\xeb\xec\xed\xee\xef\xf0\xf1\xf2\xf3\xf4\xf5\xf6\xf8\xf9\xfa\xfb\xfc\xfd\xfe\x96\xa0\x8b\x97\x9b\xa6\xad\xb7",
'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.'
'ALLSSSSTZZZallssstzzzRAAAALCCCEEEEIIDDNNOOOOxRUUUUYTsraaaalccceeeeiiddnnooooruuuuyt- <->|-.',
);
$s = self::pcre('preg_replace', ['#[^\x00-\x7F]++#', '', $s]);
} else {
31 changes: 12 additions & 19 deletions src/Utils/Type.php
Original file line number Diff line number Diff line change
@@ -52,10 +52,10 @@ public static function fromReflection($reflection): ?self
} elseif ($type instanceof \ReflectionUnionType || $type instanceof \ReflectionIntersectionType) {
return new self(
array_map(
function ($t) use ($reflection) { return self::resolve($t->getName(), $reflection); },
$type->getTypes()
fn($t) => self::resolve($t->getName(), $reflection),
$type->getTypes(),
),
$type instanceof \ReflectionUnionType ? '|' : '&'
$type instanceof \ReflectionUnionType ? '|' : '&',
);

} else {
@@ -142,7 +142,7 @@ public function getNames(): array
*/
public function getTypes(): array
{
return array_map(function ($name) { return self::fromString($name); }, $this->types);
return array_map(fn($name) => self::fromString($name), $this->types);
}


@@ -223,28 +223,21 @@ public function allows(string $type): bool
$type = self::fromString($type);

if ($this->isIntersection()) {
if (!$type->isIntersection()) {
return false;
}

return Arrays::every($this->types, function ($currentType) use ($type) {
$builtin = Reflection::isBuiltinType($currentType);
return Arrays::some($type->types, function ($testedType) use ($currentType, $builtin) {
return $builtin
return $type->isIntersection()
&& Arrays::every($this->types, function ($currentType) use ($type) {
$builtin = Reflection::isBuiltinType($currentType);
return Arrays::some($type->types, fn($testedType) => $builtin
? strcasecmp($currentType, $testedType) === 0
: is_a($testedType, $currentType, true);
: is_a($testedType, $currentType, true));
});
});
}

$method = $type->isIntersection() ? 'some' : 'every';
return Arrays::$method($type->types, function ($testedType) {
$builtin = Reflection::isBuiltinType($testedType);
return Arrays::some($this->types, function ($currentType) use ($testedType, $builtin) {
return $builtin
? strcasecmp($currentType, $testedType) === 0
: is_a($testedType, $currentType, true);
});
return Arrays::some($this->types, fn($currentType) => $builtin
? strcasecmp($currentType, $testedType) === 0
: is_a($testedType, $currentType, true));
});
}
}
Loading