diff --git a/.gitignore b/.gitignore index 86a709c..7f61bd2 100644 --- a/.gitignore +++ b/.gitignore @@ -37,6 +37,7 @@ # PHPUnit /app/phpunit.xml /phpunit.xml +.phpunit.result.cache # Build data /build/ @@ -47,5 +48,6 @@ # Backup entities generated with doctrine:generate:entities command */Entity/*~ /.php_cs.cache +/.php-cs-fixer.cache composer.lock .phpunit.result.cache diff --git a/.php-cs-fixer.php b/.php-cs-fixer.php new file mode 100644 index 0000000..80c3715 --- /dev/null +++ b/.php-cs-fixer.php @@ -0,0 +1,36 @@ +exclude('build') + ->exclude('cache') + ->exclude('var') + ->exclude('vendor') + ->in(__DIR__); + +$config = new PhpCsFixer\Config(); +$config + ->setRules([ + '@Symfony' => true, + 'ordered_class_elements' => [ + 'order' => [ + 'use_trait', + 'constant_public', + 'constant_protected', + 'constant_private', + 'property_public', + 'property_protected', + 'property_private', + 'construct', + 'destruct', + 'magic', + 'phpunit', + 'method_public', + 'method_protected', + 'method_private' + ] + ], + 'array_syntax' => ['syntax' => 'short'], + ]) + ->setFinder($finder); + +return $config; diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 74a3514..0000000 --- a/.php_cs +++ /dev/null @@ -1,19 +0,0 @@ -exclude('build') - ->exclude('cache') - ->exclude('var') - ->exclude('vendor') - ->in(__DIR__); - -$config = PhpCsFixer\Config::create(); -$config - ->setRules([ - '@Symfony' => true, - 'ordered_class_elements' => ['use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public', 'property_protected', 'property_private', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private'], - 'array_syntax' => ['syntax' => 'short'], - ]) - ->setFinder($finder); - -return $config; diff --git a/DependencyInjection/SubugoeIIIFExtension.php b/DependencyInjection/SubugoeIIIFExtension.php index cbb1645..39ce68f 100644 --- a/DependencyInjection/SubugoeIIIFExtension.php +++ b/DependencyInjection/SubugoeIIIFExtension.php @@ -2,10 +2,10 @@ namespace Subugoe\IIIFBundle\DependencyInjection; -use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\Config\FileLocator; -use Symfony\Component\HttpKernel\DependencyInjection\Extension; +use Symfony\Component\DependencyInjection\ContainerBuilder; use Symfony\Component\DependencyInjection\Loader; +use Symfony\Component\HttpKernel\DependencyInjection\Extension; /** * This is the class that loads and manages your bundle configuration. diff --git a/README.md b/README.md index 11a6619..bc54c7f 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # IIIF Bundle -This is a Symfony 3.x Bundle to get an IIIF Representation out of arbitrary data structures. +This is a Symfony 5.x Bundle to get an IIIF Representation out of arbitrary data structures. ## Example configuration diff --git a/Service/FileService.php b/Service/FileService.php index 32248e6..caeb1af 100644 --- a/Service/FileService.php +++ b/Service/FileService.php @@ -7,17 +7,11 @@ /** * Wrapper around cache and source filesystems. */ -class FileService +class FileService implements FileServiceInterface { - /** - * @var Filesystem - */ - private $cacheFilesystem; + private Filesystem $cacheFilesystem; - /** - * @var Filesystem - */ - private $sourceFilesystem; + private Filesystem $sourceFilesystem; public function __construct(Filesystem $cacheFilesystem, Filesystem $sourceFilesystem) { @@ -25,17 +19,11 @@ public function __construct(Filesystem $cacheFilesystem, Filesystem $sourceFiles $this->sourceFilesystem = $sourceFilesystem; } - /** - * @return Filesystem - */ public function getCacheFilesystem(): Filesystem { return $this->cacheFilesystem; } - /** - * @return Filesystem - */ public function getSourceFilesystem(): Filesystem { return $this->sourceFilesystem; diff --git a/Service/FileServiceInterface.php b/Service/FileServiceInterface.php new file mode 100644 index 0000000..e4f8364 --- /dev/null +++ b/Service/FileServiceInterface.php @@ -0,0 +1,15 @@ +fileService = $fileService; } - public function setImageConfiguration(array $imageConfiguration) + public function setImageConfiguration(array $imageConfiguration): void { $this->imageConfiguration = $imageConfiguration; } @@ -82,12 +67,7 @@ public function getImageConfiguration(): array return $this->imageConfiguration; } - /** - * @param \Subugoe\IIIFModel\Model\Image\Image $imageEntity - * - * @return string - */ - public function process($imageEntity) + public function process(Image $imageEntity): string { $image = $this->imagine->load($this->getOriginalFileContents($imageEntity)); @@ -103,21 +83,15 @@ public function process($imageEntity) return $image->get($imageEntity->getFormat()); } - /** - * @param string $identifier - * - * @return ImageInformation - */ public function getImageJsonInformation(string $identifier, $originalImage): ImageInformation { - $imageEntity = new \Subugoe\IIIFModel\Model\Image\Image(); + $imageEntity = new Image(); $imageEntity->setIdentifier($identifier); try { $image = $this->imagine->load($originalImage); } catch (\Exception $e) { - throw new NotFoundHttpException(sprintf('Image with identifier %s not found', - $imageEntity->getIdentifier())); + throw new NotFoundHttpException(sprintf('Image with identifier %s not found', $imageEntity->getIdentifier())); } $ppi = $image->getImagick()->getImageResolution(); @@ -145,7 +119,7 @@ public function getImageJsonInformation(string $identifier, $originalImage): Ima $imageInformation = new ImageInformation(); $imageInformation ->setId($this->router->generate('subugoe_iiif_image_base', ['identifier' => $identifier], - Router::ABSOLUTE_URL)) + UrlGeneratorInterface::ABSOLUTE_URL)) ->setPpi($ppi) ->setWidth($originalSize->getWidth()) ->setHeight($originalSize->getHeight()) @@ -158,11 +132,11 @@ public function getImageJsonInformation(string $identifier, $originalImage): Ima /** * Stores the original image in a cache file. * - * @param \Subugoe\IIIFModel\Model\Image\Image $image + * @return false|string * - * @return \Psr\Http\Message\StreamInterface|string + * @throws FilesystemException */ - public function getOriginalFileContents(\Subugoe\IIIFModel\Model\Image\Image $image) + public function getOriginalFileContents(Image $image) { $document = $this->translator->getDocumentByImageId($image->getIdentifier()); $filename = $this->getFilename($document, $image); @@ -171,11 +145,9 @@ public function getOriginalFileContents(\Subugoe\IIIFModel\Model\Image\Image $im $cacheFilesystem = $this->fileService->getCacheFilesystem(); $originalImageCacheFile = sprintf('/orig/%s.%s', $image->getIdentifier(), $document->getImageFormat()); - if ($this->imageConfiguration['originals_caching']) { - if (!$cacheFilesystem->fileExists($originalImageCacheFile)) { - $sourceImage = $sourceFilesystem->read($filename); - $cacheFilesystem->write($originalImageCacheFile, $sourceImage); - } + if ($this->imageConfiguration['originals_caching'] && !$cacheFilesystem->fileExists($originalImageCacheFile)) { + $sourceImage = $sourceFilesystem->read($filename); + $cacheFilesystem->write($originalImageCacheFile, $sourceImage); } if ($cacheFilesystem->fileExists($originalImageCacheFile)) { @@ -191,7 +163,7 @@ public function getOriginalFileContents(\Subugoe\IIIFModel\Model\Image\Image $im public function getCachedFileIdentifier(Image $image): string { - $cachedFile = vsprintf( + return vsprintf( '%s/%s.%s', [ $image->getIdentifier(), @@ -199,8 +171,6 @@ public function getCachedFileIdentifier(Image $image): string $image->getFormat(), ] ); - - return $cachedFile; } private function getImageHash(Image $image): string @@ -224,12 +194,12 @@ private function getImageHash(Image $image): string * * @return ImageInterface */ - private function getRegion(string $region, ImageInterface $image): ImageInterface + private function getRegion(string $region, ImageInterface $image): void { $region = trim($region); if ('full' === $region) { - return $image; + return; } $sourceImageWidth = $image->getSize()->getWidth(); @@ -237,7 +207,7 @@ private function getRegion(string $region, ImageInterface $image): ImageInterfac if ('square' === $region) { $regionSort = 'squareBased'; - } elseif (strpos($region, 'pct') !== false) { + } elseif (false !== strpos($region, 'pct')) { $regionSort = 'percentageBased'; } else { $regionSort = 'pixelBased'; @@ -285,8 +255,6 @@ private function getRegion(string $region, ImageInterface $image): ImageInterfac } $image->crop(new Point($x, $y), new Box($w, $h)); - - return $image; } /* @@ -308,26 +276,26 @@ private function getRegion(string $region, ImageInterface $image): ImageInterfac * * @return ImageInterface */ - private function getSize(string $size, ImageInterface $image): ImageInterface + private function getSize(string $size, ImageInterface $image): void { if ('full' === $size || 'max' === $size) { - return $image; + return; } $rawSize = $size; - if (strpos($size, '!') !== false) { + if (false !== strpos($size, '!')) { $size = str_replace('!', '', $size); } $regionWidth = $image->getSize()->getWidth(); $regionHeight = $image->getSize()->getHeight(); - if (strpos($size, 'pct') === false) { + if (false === strpos($size, 'pct')) { $requestedSize = explode(',', $size); if (2 != count($requestedSize)) { throw new BadRequestHttpException(sprintf('Bad Request: Size syntax %s is not valid.', $size)); } $width = $requestedSize[0]; $height = $requestedSize[1]; - if (strpos($rawSize, '!') !== false) { + if (false !== strpos($rawSize, '!')) { $w = (($regionWidth / $regionHeight) * $height); $h = (($regionHeight / $regionWidth) * $width); } else { @@ -343,7 +311,7 @@ private function getSize(string $size, ImageInterface $image): ImageInterface } } $image->resize(new Box($w, $h)); - } elseif (strpos($size, 'pct') !== false) { + } elseif (false !== strpos($size, 'pct')) { $requestedPercentage = explode(':', $size)[1]; if (is_numeric($requestedPercentage)) { $w = (($regionWidth * $requestedPercentage) / 100); @@ -353,8 +321,6 @@ private function getSize(string $size, ImageInterface $image): ImageInterface throw new BadRequestHttpException(sprintf('Bad Request: Size syntax %s is not valid.', $size)); } } - - return $image; } /* @@ -372,16 +338,16 @@ private function getSize(string $size, ImageInterface $image): ImageInterface * * @return ImageInterface */ - private function getRotation(string $rotation, ImageInterface $image): ImageInterface + private function getRotation(string $rotation, ImageInterface $image): void { if (0 === (int) $rotation) { - return $image; + return; } - if (isset($rotation) && !empty($rotation)) { + if (!empty($rotation)) { $rotationDegree = str_replace('!', '', $rotation); - if ((int)$rotationDegree <= 360) { - if (strpos($rotation, '!') !== false) { + if ((int) $rotationDegree <= 360) { + if (false !== strpos($rotation, '!')) { $image->flipVertically(); } $image->rotate(str_replace('!', '', $rotation)); @@ -389,8 +355,6 @@ private function getRotation(string $rotation, ImageInterface $image): ImageInte throw new BadRequestHttpException(sprintf('Bad Request: Rotation argument %s is not between 0 and 360.', $rotationDegree)); } } - - return $image; } /* @@ -411,10 +375,10 @@ private function getRotation(string $rotation, ImageInterface $image): ImageInte * * @return ImageInterface */ - private function getQuality(string $quality, ImageInterface $image): ImageInterface + private function getQuality(string $quality, ImageInterface $image): void { if ('default' === $quality || 'color' === $quality) { - return $image; + return; } switch ($quality) { @@ -430,15 +394,8 @@ private function getQuality(string $quality, ImageInterface $image): ImageInterf default: throw new BadRequestHttpException(sprintf('Bad Request: %s is not a supported quality.', $quality)); } - - return $image; } - /** - * @param BoxInterface $originalSize - * - * @return array - */ private function getImageSizes(BoxInterface $originalSize): array { $sizes = []; @@ -456,11 +413,6 @@ private function getImageSizes(BoxInterface $originalSize): array return array_reverse($sizes); } - /** - * @param array $sizeList - * - * @return array - */ private function getTileInformation(array $sizeList): array { $tiles = []; @@ -475,7 +427,7 @@ private function getTileInformation(array $sizeList): array return $tiles; } - private function getFilename(Document $document, \Subugoe\IIIFModel\Model\Image\Image $image): string + private function getFilename(Document $document, Image $image): string { /** @var PhysicalStructure $physicalStructure */ foreach ($document->getPhysicalStructures() as $physicalStructure) { diff --git a/Service/ImageServiceInterface.php b/Service/ImageServiceInterface.php new file mode 100644 index 0000000..91a2209 --- /dev/null +++ b/Service/ImageServiceInterface.php @@ -0,0 +1,30 @@ +getMetadata($document); $thumbnail = $this->getThumbnail($document); $logo = $this->getLogo(); - $sequences = $this->getSequences($document, 'normal'); + $sequences = $this->getSequences($document); $structures = $this->getStructures($document); $attribution = $this->getAttribution($document); $manifest @@ -82,7 +69,7 @@ public function getManifest(\Subugoe\IIIFModel\Model\Document $document): Docume [ 'id' => $document->getId(), ], - RouterInterface::ABSOLUTE_URL) + UrlGeneratorInterface::ABSOLUTE_URL) ) ->setLabel($document->getTitle()[0]) ->setNavDate($this->getNavDate($document)) @@ -106,17 +93,14 @@ public function getManifest(\Subugoe\IIIFModel\Model\Document $document): Docume } /** @var Document $parent */ foreach ($document->getParents() as $parent) { - $manifest->setWithin($this->router->generate('subugoe_iiif_manifest', ['id' => $parent->getId()], RouterInterface::ABSOLUTE_URL)); + $manifest->setWithin($this->router->generate('subugoe_iiif_manifest', ['id' => $parent->getId()], UrlGeneratorInterface::ABSOLUTE_URL)); } return $manifest; } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $name - * - * @return AnnotationList + * @throws IIIFException */ public function getAnnotationList(\Subugoe\IIIFModel\Model\Document $document, string $name): AnnotationList { @@ -126,7 +110,7 @@ public function getAnnotationList(\Subugoe\IIIFModel\Model\Document $document, s $annotationList->setId($this->router->generate('subugoe_iiif_annotation-list', [ 'id' => $document->getId(), 'name' => $name, - ], RouterInterface::ABSOLUTE_URL)); + ], UrlGeneratorInterface::ABSOLUTE_URL)); $resources = []; $resourceData = new ResourceData(); @@ -145,40 +129,27 @@ public function getAnnotationList(\Subugoe\IIIFModel\Model\Document $document, s return $annotationList; } - /** - * @param Collection $collection - * - * @return Collection - */ - public function getCollection(Collection $collection) + public function getCollection(Collection $collection): Collection { return $collection; } - /** - * @param Collections $collections - * - * @return Collections - */ - public function getCollections(Collections $collections) + public function getCollections(Collections $collections): Collections { return $collections; } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $name - * - * @return Range + * @throws IIIFException */ - public function getRange(\Subugoe\IIIFModel\Model\Document $document, string $name) + public function getRange(\Subugoe\IIIFModel\Model\Document $document, string $name): Range { $this->router->setContext($this->setRoutingContext(self::CONTEXT_MANIFESTS)); $range = new Range(); $range - ->setId($this->router->generate('subugoe_iiif_range', ['id' => $document->getId(), 'range' => $name], RouterInterface::ABSOLUTE_URL)) + ->setId($this->router->generate('subugoe_iiif_range', ['id' => $document->getId(), 'range' => $name], UrlGeneratorInterface::ABSOLUTE_URL)) ->setLabel($this->getLabelForRange($document, $name)) ->setMembers($this->getMembersForRange($document, $name)); @@ -186,11 +157,7 @@ public function getRange(\Subugoe\IIIFModel\Model\Document $document, string $na } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $canvasId - * @param int $physicalStructureId - * - * @return Canvas + * @throws IIIFException */ public function getCanvas(\Subugoe\IIIFModel\Model\Document $document, string $canvasId, int $physicalStructureId = -1): Canvas { @@ -210,7 +177,7 @@ public function getCanvas(\Subugoe\IIIFModel\Model\Document $document, string $c 'id' => $document->getId(), 'canvas' => $canvasId, ], - RouterInterface::ABSOLUTE_URL)) + UrlGeneratorInterface::ABSOLUTE_URL)) ->setLabel($label) ->setHeight(400) ->setWidth(300) @@ -219,7 +186,7 @@ public function getCanvas(\Subugoe\IIIFModel\Model\Document $document, string $c if (!empty($document->getPhysicalStructure($physicalStructureId)->getAnnotation())) { $annotationList = new AnnotationList(); $annotationList - ->setId($this->router->generate('subugoe_iiif_annotation-list', ['id' => $document->getId(), 'name' => $canvasId], RouterInterface::ABSOLUTE_URL)) + ->setId($this->router->generate('subugoe_iiif_annotation-list', ['id' => $document->getId(), 'name' => $canvasId], UrlGeneratorInterface::ABSOLUTE_URL)) ->setType('sc:AnnotationList'); $canvas->setOtherContent([$annotationList]); @@ -229,10 +196,7 @@ public function getCanvas(\Subugoe\IIIFModel\Model\Document $document, string $c } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $imageId - * - * @return GenericResource + * @throws IIIFException */ public function getImage(\Subugoe\IIIFModel\Model\Document $document, string $imageId): GenericResource { @@ -247,7 +211,7 @@ public function getImage(\Subugoe\IIIFModel\Model\Document $document, string $im $image = new GenericResource(); $resource = new ResourceData(); - $mimes = new \Mimey\MimeTypes(); + $mimes = new MimeTypes(); $format = $mimes->getMimeType($document->getImageFormat()) ?: ''; @@ -256,31 +220,28 @@ public function getImage(\Subugoe\IIIFModel\Model\Document $document, string $im $imageService = new Service(); $imageService ->setId($this->router->generate( - 'subugoe_iiif_image_base', ['identifier' => $imageParameters['identifier']], RouterInterface::ABSOLUTE_URL)); + 'subugoe_iiif_image_base', ['identifier' => $imageParameters['identifier']], UrlGeneratorInterface::ABSOLUTE_URL)); $this->router->setContext($this->setRoutingContext(self::CONTEXT_MANIFESTS)); $resource - ->setId($this->router->generate('subugoe_iiif_image_base', ['identifier' => $imageParameters['identifier']], RouterInterface::ABSOLUTE_URL)) + ->setId($this->router->generate('subugoe_iiif_image_base', ['identifier' => $imageParameters['identifier']], UrlGeneratorInterface::ABSOLUTE_URL)) ->setFormat($format) ->setWidth(300) ->setHeight(400) ->setService($imageService); $image - ->setId($this->router->generate('subugoe_iiif_imagepresentation', ['id' => $document->getId(), 'name' => $imageId], RouterInterface::ABSOLUTE_URL)) + ->setId($this->router->generate('subugoe_iiif_imagepresentation', ['id' => $document->getId(), 'name' => $imageId], UrlGeneratorInterface::ABSOLUTE_URL)) ->setResource($resource) - ->setOn($this->router->generate('subugoe_iiif_canvas', ['id' => $document->getId(), 'canvas' => $imageId], RouterInterface::ABSOLUTE_URL)); + ->setOn($this->router->generate('subugoe_iiif_canvas', ['id' => $document->getId(), 'canvas' => $imageId], UrlGeneratorInterface::ABSOLUTE_URL)); return $image; } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $name - * - * @return Sequence + * @throws IIIFException */ - public function getSequence(\Subugoe\IIIFModel\Model\Document $document, $name): Sequence + public function getSequence(\Subugoe\IIIFModel\Model\Document $document, string $name): Sequence { $this->router->setContext($this->setRoutingContext(self::CONTEXT_MANIFESTS)); @@ -292,22 +253,18 @@ public function getSequence(\Subugoe\IIIFModel\Model\Document $document, $name): 'id' => $document->getId(), 'name' => $name, ], - RouterInterface::ABSOLUTE_URL)) + UrlGeneratorInterface::ABSOLUTE_URL)) ->setCanvases($canvases) ->setStartCanvas($this->router->generate('subugoe_iiif_canvas', [ 'id' => $document->getId(), 'canvas' => $document->getPhysicalStructure(0)->getIdentifier(), ], - RouterInterface::ABSOLUTE_URL)); + UrlGeneratorInterface::ABSOLUTE_URL)); return $sequence; } /** - * @param string $type - * - * @return RequestContext - * * @throws IIIFException */ private function setRoutingContext(string $type): RequestContext @@ -352,12 +309,6 @@ private function setRoutingContext(string $type): RequestContext return $this->router->getContext(); } - /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $identifier - * - * @return int - */ private function getPagePositionByIdentifier(\Subugoe\IIIFModel\Model\Document $document, string $identifier): int { $position = 0; @@ -369,16 +320,13 @@ private function getPagePositionByIdentifier(\Subugoe\IIIFModel\Model\Document $ ++$position; } - throw new \InvalidArgumentException(sprintf('Page with label %s not found in document %s', $identifier, $document->getId()), 1490689215); + throw new InvalidArgumentException(sprintf('Page with label %s not found in document %s', $identifier, $document->getId()), 1490689215); } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $range - * - * @return array + * @throws IIIFException */ - private function getMembersForRange(\Subugoe\IIIFModel\Model\Document $document, string $range) + private function getMembersForRange(\Subugoe\IIIFModel\Model\Document $document, string $range): array { $logicalStructures = $document->getLogicalStructures(); $numberOflogicalStructures = count($logicalStructures); @@ -397,14 +345,9 @@ private function getMembersForRange(\Subugoe\IIIFModel\Model\Document $document, return []; } - /** - * @param \Subugoe\IIIFModel\Model\Document $document - * - * @return \DateTime - */ - private function getNavDate(\Subugoe\IIIFModel\Model\Document $document) + private function getNavDate(\Subugoe\IIIFModel\Model\Document $document): DateTime { - return \DateTime::createFromFormat('Y-m-d H:i:s', vsprintf('%d-%s-%s %s:%s:%s', + return DateTime::createFromFormat('Y-m-d H:i:s', vsprintf('%d-%s-%s %s:%s:%s', [ $document->getPublishingYear(), '01', @@ -417,9 +360,6 @@ private function getNavDate(\Subugoe\IIIFModel\Model\Document $document) } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * - * @return Image * @throws IIIFException */ private function getThumbnail(\Subugoe\IIIFModel\Model\Document $document): Image @@ -428,7 +368,7 @@ private function getThumbnail(\Subugoe\IIIFModel\Model\Document $document): Imag $thumbnail = new Image(); $thumbnailService = new Service(); - $thumbnailService->setId($this->router->generate('subugoe_iiif_manifest', ['id' => $document->getId()], RouterInterface::ABSOLUTE_URL)); + $thumbnailService->setId($this->router->generate('subugoe_iiif_manifest', ['id' => $document->getId()], UrlGeneratorInterface::ABSOLUTE_URL)); $thumbnailParameters = [ 'identifier' => $document->getPhysicalStructure(0)->getIdentifier(), @@ -442,7 +382,7 @@ private function getThumbnail(\Subugoe\IIIFModel\Model\Document $document): Imag $thumbnail->setId($this->router->generate( 'subugoe_iiif_image', $thumbnailParameters, - RouterInterface::ABSOLUTE_URL + UrlGeneratorInterface::ABSOLUTE_URL ) ); $thumbnail->setService($thumbnailService); @@ -450,9 +390,6 @@ private function getThumbnail(\Subugoe\IIIFModel\Model\Document $document): Imag return $thumbnail; } - /** - * @return Image - */ private function getLogo(): Image { $logo = new Image(); @@ -466,11 +403,6 @@ private function getLogo(): Image return $logo; } - /** - * @param \Subugoe\IIIFModel\Model\Document $document - * - * @return array - */ private function getMetadata(\Subugoe\IIIFModel\Model\Document $document): array { $metadata = []; @@ -503,11 +435,6 @@ private function getStructureMetadata(LogicalStructure $structure): array return $metadata; } - /** - * @param \Subugoe\IIIFModel\Model\Document $document - * - * @return string - */ private function getAttribution(\Subugoe\IIIFModel\Model\Document $document): string { if (array_key_exists('0', $document->getRightsOwner())) { @@ -518,9 +445,8 @@ private function getAttribution(\Subugoe\IIIFModel\Model\Document $document): st } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * - * @return array + * @throws IIIFException + * @throws Exception */ private function getStructures(\Subugoe\IIIFModel\Model\Document $document): array { @@ -543,7 +469,7 @@ private function getStructures(\Subugoe\IIIFModel\Model\Document $document): arr ->setId($this->router->generate('subugoe_iiif_range', [ 'id' => $document->getId(), 'range' => $logicalStructure->getId(), - ], RouterInterface::ABSOLUTE_URL) + ], UrlGeneratorInterface::ABSOLUTE_URL) ) ->setLabel($logicalStructure->getLabel()) ->setType('sc:Canvas') @@ -556,7 +482,7 @@ private function getStructures(\Subugoe\IIIFModel\Model\Document $document): arr $structure->setWithin($this->router->generate('subugoe_iiif_range', [ 'id' => $document->getId(), 'range' => $parentStructure->getId(), - ], RouterInterface::ABSOLUTE_URL)); + ], UrlGeneratorInterface::ABSOLUTE_URL)); } $structures[] = $structure; @@ -568,13 +494,7 @@ private function getStructures(\Subugoe\IIIFModel\Model\Document $document): arr } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param LogicalStructure $structure - * @param int $position - * - * @throws \Exception - * - * @return LogicalStructure + * @throws Exception */ private function getPreviousHierarchyStructure(\Subugoe\IIIFModel\Model\Document $document, LogicalStructure $structure, int $position): LogicalStructure { @@ -587,20 +507,13 @@ private function getPreviousHierarchyStructure(\Subugoe\IIIFModel\Model\Document } } - throw new DataException(vsprintf( - 'Parent structure at position %d with level %d and parent level %d not defined', [ - $position, $level, $parentLevel, - ] - ), 1494506264); + throw new DataException(vsprintf('Parent structure at position %d with level %d and parent level %d not defined', [$position, $level, $parentLevel]), 1494506264); } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param LogicalStructure $logicalStructure - * - * @return array + * @throws IIIFException */ - private function getMembersOfLogicalStructure(\Subugoe\IIIFModel\Model\Document $document, LogicalStructure $logicalStructure) + private function getMembersOfLogicalStructure(\Subugoe\IIIFModel\Model\Document $document, LogicalStructure $logicalStructure): array { $this->router->setContext($this->setRoutingContext(self::CONTEXT_MANIFESTS)); @@ -614,21 +527,16 @@ private function getMembersOfLogicalStructure(\Subugoe\IIIFModel\Model\Document $canvases[] = $this->router->generate('subugoe_iiif_canvas', [ 'id' => $document->getId(), 'canvas' => $document->getPhysicalStructure($structureStart + $i)->getIdentifier(), - ], RouterInterface::ABSOLUTE_URL); + ], UrlGeneratorInterface::ABSOLUTE_URL); } return $canvases; } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param int $page - * * @throws MalformedDocumentException - * - * @return int */ - private function getPositionOfPhysicalPage(\Subugoe\IIIFModel\Model\Document $document, int $page) + private function getPositionOfPhysicalPage(\Subugoe\IIIFModel\Model\Document $document, int $page): int { $i = 0; /** @var PhysicalStructure $structure */ @@ -639,21 +547,13 @@ private function getPositionOfPhysicalPage(\Subugoe\IIIFModel\Model\Document $do ++$i; } // PPN617021074 - throw new MalformedDocumentException(vsprintf( - 'Document %s may contain an invalid or inconsistent structure. Page %d not found in %d iterations.', [ - $document->getId(), - $page, - $i, - ])); + throw new MalformedDocumentException(vsprintf('Document %s may contain an invalid or inconsistent structure. Page %d not found in %d iterations.', [$document->getId(), $page, $i])); } /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $name - * - * @return Sequence + * @throws IIIFException */ - private function getSequences(\Subugoe\IIIFModel\Model\Document $document, string $name): Sequence + private function getSequences(\Subugoe\IIIFModel\Model\Document $document): Sequence { $this->router->setContext($this->setRoutingContext(self::CONTEXT_MANIFESTS)); @@ -663,27 +563,21 @@ private function getSequences(\Subugoe\IIIFModel\Model\Document $document, strin $sequences ->setId($this->router->generate('subugoe_iiif_sequence', [ 'id' => $document->getId(), - 'name' => $name, + 'name' => 'normal', ], - RouterInterface::ABSOLUTE_URL)) + UrlGeneratorInterface::ABSOLUTE_URL)) ->setContext('') ->setCanvases($canvases) ->setStartCanvas($this->router->generate('subugoe_iiif_canvas', [ 'id' => $document->getId(), 'canvas' => $document->getPhysicalStructure(0)->getIdentifier(), ], - RouterInterface::ABSOLUTE_URL)); + UrlGeneratorInterface::ABSOLUTE_URL)); return $sequences; } - /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $canvasId - * - * @return string - */ - private function getLabelForCanvas(\Subugoe\IIIFModel\Model\Document $document, string $canvasId) + private function getLabelForCanvas(\Subugoe\IIIFModel\Model\Document $document, string $canvasId): string { $physicalStructures = $document->getPhysicalStructures(); @@ -697,13 +591,7 @@ private function getLabelForCanvas(\Subugoe\IIIFModel\Model\Document $document, return ''; } - /** - * @param \Subugoe\IIIFModel\Model\Document $document - * @param string $rangeId - * - * @return string - */ - private function getLabelForRange(\Subugoe\IIIFModel\Model\Document $document, string $rangeId) + private function getLabelForRange(\Subugoe\IIIFModel\Model\Document $document, string $rangeId): string { $logicalStructures = $document->getLogicalStructures(); @@ -718,21 +606,13 @@ private function getLabelForRange(\Subugoe\IIIFModel\Model\Document $document, s } /** - * @param \Subugoe\IIIFModel\Model\Document $document Document ID - * @param string $canvasId - * - * @return array + * @throws IIIFException */ private function getImages(\Subugoe\IIIFModel\Model\Document $document, string $canvasId): array { return [$this->getImage($document, $canvasId)]; } - /** - * @param \Subugoe\IIIFModel\Model\Document $document - * - * @return array - */ private function getCanvases(\Subugoe\IIIFModel\Model\Document $document): array { $canvases = []; diff --git a/Service/PresentationServiceInterface.php b/Service/PresentationServiceInterface.php new file mode 100644 index 0000000..5a1b8e2 --- /dev/null +++ b/Service/PresentationServiceInterface.php @@ -0,0 +1,38 @@ +document = new Document(); } - public function testSettingMetadataWithAnArrayReturnsArray() + public function testSettingMetadataWithAnArrayReturnsArray(): void { $this->document->setMetadata([]); $this->assertSame($this->document->getMetadata(), []); diff --git a/Tests/Model/LogicalStructureTest.php b/Tests/Model/LogicalStructureTest.php index d1a7376..f0c0681 100644 --- a/Tests/Model/LogicalStructureTest.php +++ b/Tests/Model/LogicalStructureTest.php @@ -10,17 +10,14 @@ */ class LogicalStructureTest extends TestCase { - /** - * @var LogicalStructure - */ - private $logicalStructure; + private LogicalStructure $logicalStructure; protected function setUp(): void { $this->logicalStructure = new LogicalStructure(); } - public function testSettingTheIdSetsTheId() + public function testSettingTheIdSetsTheId(): void { $id = 'guzu'; @@ -28,7 +25,7 @@ public function testSettingTheIdSetsTheId() $this->assertSame($id, $this->logicalStructure->getId()); } - public function testSettingTheLabelSetsTheLabel() + public function testSettingTheLabelSetsTheLabel(): void { $label = 'guzu'; @@ -36,7 +33,7 @@ public function testSettingTheLabelSetsTheLabel() $this->assertSame($label, $this->logicalStructure->getLabel()); } - public function testSettingTheTypeReturnsTheType() + public function testSettingTheTypeReturnsTheType(): void { $type = 'guzu'; @@ -44,7 +41,7 @@ public function testSettingTheTypeReturnsTheType() $this->assertSame($type, $this->logicalStructure->getType()); } - public function testStartPageSetsTheStartPage() + public function testStartPageSetsTheStartPage(): void { $startPage = 100; @@ -52,7 +49,7 @@ public function testStartPageSetsTheStartPage() $this->assertSame($startPage, $this->logicalStructure->getStartPage()); } - public function testEndPageSetsTheStartPage() + public function testEndPageSetsTheStartPage(): void { $endPage = 100; @@ -60,7 +57,7 @@ public function testEndPageSetsTheStartPage() $this->assertSame($endPage, $this->logicalStructure->getEndPage()); } - public function testSettingTheLevelSetsTheLabel() + public function testSettingTheLevelSetsTheLabel(): void { $level = 100; diff --git a/Tests/Service/FileServiceTest.php b/Tests/Service/FileServiceTest.php index ce5bea8..ad26cc9 100644 --- a/Tests/Service/FileServiceTest.php +++ b/Tests/Service/FileServiceTest.php @@ -9,10 +9,7 @@ class FileServiceTest extends TestCase { - /** - * @var FileService - */ - protected $fileService; + protected FileService $fileService; protected function setUp(): void { @@ -22,7 +19,7 @@ protected function setUp(): void $this->fileService = new FileService($cache, $source); } - public function testRetrievalOfCacheFilesystemReturnsFilesystem() + public function testRetrievalOfCacheFilesystemReturnsFilesystem(): void { $this->assertInstanceOf(Filesystem::class, $this->fileService->getCacheFilesystem()); $this->assertInstanceOf(Filesystem::class, $this->fileService->getSourceFilesystem()); diff --git a/Tests/Service/ImageServiceTest.php b/Tests/Service/ImageServiceTest.php index 4c0406f..a79728d 100644 --- a/Tests/Service/ImageServiceTest.php +++ b/Tests/Service/ImageServiceTest.php @@ -3,8 +3,8 @@ namespace Subugoe\IIIFBundle\Tests\Service; use PHPUnit\Framework\TestCase; -use Subugoe\IIIFModel\Model\Image\Image; use Subugoe\IIIFBundle\Service\ImageService; +use Subugoe\IIIFModel\Model\Image\Image; class ImageServiceTest extends TestCase { @@ -24,7 +24,7 @@ protected function setUp(): void $this->imageService = $imageService; } - public function testIdentifierCalculation() + public function testIdentifierCalculation(): void { $image = (new Image())->setIdentifier('a'); $image->setFormat('jpg'); diff --git a/Tests/Service/PresentationServiceTest.php b/Tests/Service/PresentationServiceTest.php index ab5c2c9..6d67e4b 100644 --- a/Tests/Service/PresentationServiceTest.php +++ b/Tests/Service/PresentationServiceTest.php @@ -3,6 +3,7 @@ namespace Subugoe\IIIFBundle\Tests\Service; use PHPUnit\Framework\TestCase; +use Subugoe\IIIFBundle\Exception\MalformedDocumentException; use Subugoe\IIIFBundle\Service\PresentationService; use Subugoe\IIIFBundle\Tests\Translator\TranslatorMock; use Subugoe\IIIFBundle\Translator\TranslatorInterface; @@ -45,10 +46,7 @@ protected function setUp(): void $this->presentationService = new PresentationService($router, $imageConfiguration, $presentationConfiguration); } - /** - * @return array - */ - public function documentProvider() + public function documentProvider(): array { return [ ['PPN613131266'], @@ -57,10 +55,7 @@ public function documentProvider() ]; } - /** - * @return array - */ - public function annotationProvider() + public function annotationProvider(): array { return [ ['PPN613131266', false], @@ -70,7 +65,7 @@ public function annotationProvider() ]; } - public function malformedDocumentProvider() + public function malformedDocumentProvider(): array { return [ ['PPN599471603_0013'], @@ -79,10 +74,7 @@ public function malformedDocumentProvider() ]; } - /** - * @return array - */ - public function RangeProvider() + public function RangeProvider(): array { return [ ['PPN613131266', 27], @@ -92,7 +84,7 @@ public function RangeProvider() /** * @dataProvider documentProvider */ - public function testSequences($id) + public function testSequences($id): void { $document = $this->translator->getDocumentById($id); $this->presentationService->getManifest($document); @@ -101,7 +93,7 @@ public function testSequences($id) /** * @dataProvider rangeProvider */ - public function testRanges($id, $count) + public function testRanges($id, $count): void { $document = $this->translator->getDocumentById($id); $ranges = $this->presentationService->getRange($document, 'LOG_0003'); @@ -112,7 +104,7 @@ public function testRanges($id, $count) /** * @dataProvider annotationProvider */ - public function testAnnotationExistance($id, $expected) + public function testAnnotationExistance($id, $expected): void { $document = $this->translator->getDocumentById($id); $this->assertSame(!empty($document->getPhysicalStructure(0)->getAnnotation()), $expected); @@ -120,17 +112,14 @@ public function testAnnotationExistance($id, $expected) /** * @dataProvider malformedDocumentProvider - * @expectedException \Subugoe\IIIFBundle\Exception\MalformedDocumentException */ - public function testMalformedDocument($id) + public function testMalformedDocument($id): void { + $this->expectException(MalformedDocumentException::class); $document = $this->translator->getDocumentById($id); $this->presentationService->getManifest($document); } - /** - * @return \Symfony\Bundle\FrameworkBundle\Routing\Router - */ protected function getRouterMock() { $mock = $this->getMockBuilder(Router::class) diff --git a/Tests/Translator/TranslatorMock.php b/Tests/Translator/TranslatorMock.php index 006f88b..ec42886 100644 --- a/Tests/Translator/TranslatorMock.php +++ b/Tests/Translator/TranslatorMock.php @@ -2,13 +2,13 @@ namespace Subugoe\IIIFBundle\Tests\Translator; +use Subugoe\IIIFBundle\Translator\TranslatorInterface; use Subugoe\IIIFModel\Model\Document; use Subugoe\IIIFModel\Model\DocumentInterface; use Subugoe\IIIFModel\Model\DocumentTypes; use Subugoe\IIIFModel\Model\LogicalStructure; use Subugoe\IIIFModel\Model\PhysicalStructure; use Subugoe\IIIFModel\Model\Presentation\Collection; -use Subugoe\IIIFBundle\Translator\TranslatorInterface; /** * For testing purposes. @@ -8190,11 +8190,6 @@ class TranslatorMock implements TranslatorInterface ], ]; - /** - * @param string $id - * - * @return Document - */ public function getDocumentById(string $id): Document { $document = new Document(); @@ -8266,32 +8261,22 @@ public function getDocumentById(string $id): Document return $document; } - /** - * @param string $imageId - * - * @return Document - */ public function getDocumentByImageId(string $imageId): Document { return $this->getDocumentById($this->documents[0]); } - /** - * @param string $collectionId - * - * @return Collection - */ - public function getCollectionById(string $collectionId) + public function getCollectionById(string $collectionId): Collection { return new Collection(); } - /** - * @param string $doctype - * - * @return string - */ - private function getMappedDocumentType(string $doctype) + public function getDocumentBy(string $field, string $value, array $fields = []): DocumentInterface + { + // TODO: Implement getDocumentBy() method. + } + + private function getMappedDocumentType(string $doctype): string { $typeMapping = [ 'monograph' => DocumentTypes::MONOGRAPH, @@ -8318,9 +8303,4 @@ private function getMetadata(): array return $metadata; } - - public function getDocumentBy(string $field, string $value, array $fields = []): DocumentInterface - { - // TODO: Implement getDocumentBy() method. - } } diff --git a/Translator/SubugoeTranslator.php b/Translator/SubugoeTranslator.php index 7794318..a8ecdb1 100644 --- a/Translator/SubugoeTranslator.php +++ b/Translator/SubugoeTranslator.php @@ -46,11 +46,6 @@ class SubugoeTranslator implements TranslatorInterface /** * SubugoeTranslator constructor. - * - * @param SearchService $searchService - * @param RouterInterface $router - * @param \Symfony\Component\Translation\TranslatorInterface $translator - * @param string $rootDirectory */ public function __construct(SearchService $searchService, RouterInterface $router, \Symfony\Component\Translation\TranslatorInterface $translator, string $rootDirectory, array $collections) { @@ -62,8 +57,6 @@ public function __construct(SearchService $searchService, RouterInterface $route } /** - * @param string $collectionId - * * @return Collection */ public function getCollectionById(string $collectionId) @@ -96,11 +89,6 @@ public function getCollections() return $collections; } - /** - * @param string $id - * - * @return Document - */ public function getDocumentById(string $id): Document { $document = new Document(); @@ -187,11 +175,6 @@ public function getDocumentById(string $id): Document return $document; } - /** - * @param string $imageId - * - * @return Document - */ public function getDocumentByImageId(string $imageId): Document { $solrDocument = $this->searchService->getDocumentBy('page_key', $imageId, ['id']); @@ -199,6 +182,11 @@ public function getDocumentByImageId(string $imageId): Document return $this->getDocumentById($solrDocument['id']); } + public function getDocumentBy(string $field, string $value, array $fields = []): DocumentInterface + { + // TODO: Implement getDocumentBy() method. + } + private function getAdditionalIdentifiers(DocumentInterface $solrDocument): array { $ids = []; @@ -233,7 +221,7 @@ private function getMetadata(DocumentInterface $solrDocument, Document $document if (isset($solrDocument['creator'])) { $author = $this->getLinkedMetadata($solrDocument['creator'], true, 'facet_creator_personal'); - if ($author !== []) { + if ([] !== $author) { $metadata[$this->translateLabel('author', count($author))] = $author; } } @@ -241,7 +229,7 @@ private function getMetadata(DocumentInterface $solrDocument, Document $document if (isset($solrDocument['place_publish'])) { $place = $this->getLinkedMetadata($solrDocument['place_publish'], false); - if ($place !== []) { + if ([] !== $place) { $metadata[$this->translateLabel('place', count($place))] = $place; } } @@ -257,7 +245,7 @@ private function getMetadata(DocumentInterface $solrDocument, Document $document if (isset($solrDocument['publisher'])) { $publisher = $this->getLinkedMetadata($solrDocument['publisher'], true, 'facet_publisher'); - if ($publisher !== []) { + if ([] !== $publisher) { $metadata[$this->translateLabel('publisher')] = $publisher; } } @@ -377,7 +365,7 @@ private function getLinkedMetadata(array $metadata, bool $link, string $facet = { $metadataArr = []; - if (is_array($metadata) && $metadata !== []) { + if (is_array($metadata) && [] !== $metadata) { foreach ($metadata as $key => $value) { if (!empty($value) && !empty($facet) && $link) { $url = $this->router->generate('_homepage', ["filter[${key}][${facet}]" => $value], RouterInterface::ABSOLUTE_URL); @@ -395,7 +383,7 @@ private function getLinkedMetadata(array $metadata, bool $link, string $facet = private function getRelated(array $catalogue): array { $relatedArr = []; - if (is_array($catalogue) && $catalogue !== []) { + if (is_array($catalogue) && [] !== $catalogue) { foreach ($catalogue as $value) { $catalogueArr = explode(' ', trim($value)); $related = new Related(); @@ -412,9 +400,4 @@ private function getRelated(array $catalogue): array return $relatedArr; } - - public function getDocumentBy(string $field, string $value, array $fields = []): DocumentInterface - { - // TODO: Implement getDocumentBy() method. - } } diff --git a/Translator/TranslatorInterface.php b/Translator/TranslatorInterface.php index 5731051..2ea1228 100644 --- a/Translator/TranslatorInterface.php +++ b/Translator/TranslatorInterface.php @@ -9,32 +9,13 @@ interface TranslatorInterface { - /** - * @param string $id - * - * @return DocumentInterface - */ public function getDocumentById(string $id): DocumentInterface; - /** - * @param string $field - * @param string $value - * @param array $fields - * - * @return DocumentInterface - */ public function getDocumentBy(string $field, string $value, array $fields = []): DocumentInterface; - /** - * @param string $imageId - * - * @return DocumentInterface - */ public function getDocumentByImageId(string $imageId): DocumentInterface; /** - * @param string $collectionId - * * @return Collection */ public function getCollectionById(string $collectionId); diff --git a/composer.json b/composer.json index 764b023..1ddbef8 100644 --- a/composer.json +++ b/composer.json @@ -19,6 +19,7 @@ "psr-4": { "Subugoe\\IIIFBundle\\Tests\\": "Tests/" } }, "require": { + "php": "^7.4 || ^8.0", "ext-gd": "*", "ext-imagick": "*", "jms/serializer-bundle": "^3.0", diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 63034a5..ef1bdbc 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,5 +1,5 @@ - + ./