Skip to content

Commit c0c16d7

Browse files
committed
Composer: remove typertion/php dependency
1 parent 4f91c1a commit c0c16d7

5 files changed

Lines changed: 29 additions & 17 deletions

File tree

‎composer.json‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,7 @@
99
"php": ">=8.1",
1010
"nette/utils": "^3.2",
1111
"league/flysystem": "^1.1",
12-
"psr/event-dispatcher": "^1.0",
13-
"typertion/php": "~1.0.1"
12+
"psr/event-dispatcher": "^1.0"
1413
},
1514
"require-dev": {
1615
"codeception/codeception": "^5.0.13",

‎src/Bridge/Gumlet/GumletLinkGenerator.php‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
use Contributte\Imagist\PathInfo\PathInfoFactoryInterface;
1414
use Contributte\Imagist\Resolver\DefaultImageResolverInterface;
1515
use InvalidArgumentException;
16-
use Typertion\Php\TypeAssert;
16+
use LogicException;
1717

1818
final class GumletLinkGenerator implements LinkGeneratorInterface
1919
{
@@ -100,7 +100,11 @@ private function createPath(PersistentImageInterface $image, array $options): st
100100
self::GUMLET_CONTEXT_KEY => true,
101101
]));
102102

103-
$addons = isset($options['addons']) ? TypeAssert::array($options['addons']) : [];
103+
$addons = $options['addons'] ?? [];
104+
105+
if (!is_array($addons)) {
106+
throw new LogicException(sprintf('Addons must be array, %s given.', get_debug_type($addons)));
107+
}
104108

105109
$query = array_merge($addons, $query);
106110

‎src/Bridge/Nette/Filter/NetteResourceFactory.php‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
use Contributte\Imagist\File\FileInterface;
66
use Contributte\Imagist\Filter\Context\ContextInterface;
77
use Contributte\Imagist\Filter\Resource\ResourceFactoryInterface;
8+
use InvalidArgumentException;
89
use Nette\Utils\Image;
9-
use Typertion\Php\TypeAssert;
1010

1111
final class NetteResourceFactory implements ResourceFactoryInterface
1212
{
@@ -22,10 +22,13 @@ public function toString(object $resource, FileInterface $source, ContextInterfa
2222
{
2323
assert($resource instanceof Image);
2424

25-
return $resource->toString(
26-
$source->getMimeType()->getImageType(),
27-
TypeAssert::intOrNull($context->get(self::QUALITY_CONTEXT))
28-
);
25+
$quality = $context->get(self::QUALITY_CONTEXT);
26+
27+
if (!is_int($quality) && $quality !== null) {
28+
throw new InvalidArgumentException(sprintf('Quality must be int or null, %s given', get_debug_type($quality)));
29+
}
30+
31+
return $resource->toString($source->getMimeType()->getImageType(), $quality);
2932
}
3033

3134
}

‎src/Bridge/Nette/Form/ImageUploadControl.php‎

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
use Nette\Forms\Controls\UploadControl;
1616
use Nette\Http\FileUpload;
1717
use Nette\Utils\Html;
18-
use Typertion\Php\TypeAssert;
1918

2019
final class ImageUploadControl extends UploadControl
2120
{
@@ -44,7 +43,11 @@ public function loadHttpData(): void
4443
{
4544
parent::loadHttpData();
4645

47-
$this->setValue($this->uploadValue = TypeAssert::instanceOfOrNull($this->value, FileUpload::class));
46+
if (!$this->value instanceof FileUpload) {
47+
throw new LogicException(sprintf('Value must be %s, %s given', FileUpload::class, get_debug_type($this->value)));
48+
}
49+
50+
$this->setValue($this->uploadValue = $this->value);
4851

4952
if ($this->remove) {
5053
$removeAnyway = $this->remove->getHttpData($this);

‎src/Remover/PersistentImageRemover.php‎

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@
1111
use Contributte\Imagist\Filter\Internal\VoidFilter;
1212
use Contributte\Imagist\PathInfo\PathInfoFactoryInterface;
1313
use DomainException;
14-
use Typertion\Php\ArrayTypeAssert;
15-
use Typertion\Php\TypeAssert;
1614

1715
final class PersistentImageRemover implements RemoverInterface
1816
{
@@ -52,14 +50,19 @@ private function removeFiltered(PersistentImageInterface $image): void
5250
$path = $this->pathInfoFactory->create($image->withFilter(new VoidFilter('void')));
5351

5452
foreach ($this->filesystem->listContents($path->toString($path::BUCKET | $path::SCOPE)) as $path) {
55-
$path = TypeAssert::array($path);
53+
if (!is_array($path)) {
54+
continue;
55+
}
5656

57-
if (ArrayTypeAssert::string($path, 'type') !== 'dir') {
57+
$pathType = $path['type'] ?? '';
58+
59+
if (!is_string($pathType) || $pathType !== 'dir') {
5860
continue;
5961
}
6062

61-
$filename = isset($path['filename']) ? TypeAssert::string($path['filename']) : '';
62-
if (!$filename || $filename[0] !== '_') {
63+
$filename = $path['filename'] ?? '';
64+
65+
if (!is_string($filename) || !$filename || $filename[0] !== '_') {
6366
continue;
6467
}
6568

0 commit comments

Comments
 (0)