Skip to content

Commit cf997e1

Browse files
committed
Fix various code stinks
1 parent 4a6f234 commit cf997e1

34 files changed

+118
-85
lines changed

src/Iiif/Context/JsonLdProcessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ public function processContext($localContext, JsonLdContext $activeContext, $rem
262262
} elseif (IRI::isAbsoluteIri($value)) {
263263
// 5.7.3)
264264
$result->setBaseIri($value);
265-
} elseif (IRI::isRelativeIri($uri) && $result->getBaseIri() != null) {
265+
} elseif (IRI::isRelativeIri($value) && $result->getBaseIri() != null) {
266266
// 5.7.4)
267267
$result->setBaseIri(IRI::resolveAbsoluteIri($result->getBaseIri(), $value));
268268
} else {

src/Iiif/Presentation/Common/Model/AbstractIiifEntity.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434

3535
abstract class AbstractIiifEntity {
3636

37+
protected ?string $id = null;
38+
3739
/**
3840
*
3941
* @var array

src/Iiif/Presentation/Common/Model/LazyLoadingIterator.php

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,21 @@ public function __construct(&$entity, $field, &$items) {
3636
$this->items = &$items;
3737
}
3838

39-
public function next() {
39+
public function next(): void
40+
{
4041
$this->position++;
4142
}
4243

43-
public function valid() {
44+
public function valid(): bool
45+
{
4446
return $this->items != null && $this->position < sizeof($this->items);
4547
}
4648

4749
/**
48-
* @return AbstractIiifEntity
50+
* @return ?AbstractIiifEntity
4951
*/
50-
public function current() {
52+
public function current(): ?AbstractIiifEntity
53+
{
5154
if (!$this->valid()) {
5255
return null;
5356
}
@@ -62,11 +65,12 @@ public function current() {
6265
return $this->items[$this->position];
6366
}
6467

65-
public function rewind() {
68+
public function rewind(): void
69+
{
6670
$this->position = 0;
6771
}
6872

69-
public function key() {
73+
public function key(): ?int {
7074
return $this->valid() ? $this->position : null;
7175
}
7276

src/Iiif/Presentation/Common/Model/Resources/AbstractIiifResource.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@
2424
use Ubl\Iiif\Context\JsonLdHelper;
2525

2626
abstract class AbstractIiifResource extends AbstractIiifEntity implements IiifResourceInterface {
27-
27+
28+
protected abstract function getValueForDisplay($value, $language = null, $joinChars = "; ", $options = IiifResourceInterface::SANITIZE_XML_ENCODE_NONHTML): string|array|null;
29+
2830
protected function getWeblinksForDisplayCommon($value, $language, $joinChars, $idOrAlias) {
2931
if (empty($value)) {
3032
return null;

src/Iiif/Presentation/Common/Model/Resources/AnnotationContainerInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ interface AnnotationContainerInterface extends IiifResourceInterface {
3434
* @link https://www.w3.org/TR/annotation-vocab/#motivation
3535
*
3636
*/
37-
public function getTextAnnotations($motivation = null);
37+
public function getTextAnnotations($motivation = null): ?array;
3838

3939
}
4040

src/Iiif/Presentation/Common/Model/Resources/AnnotationInterface.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ public function getBody();
3535
public function getMotivation();
3636

3737
/**
38-
* @return string The id of the resource (usually a Canvas) that is referenced by
38+
* @return ?string The id of the resource (usually a Canvas) that is referenced by
3939
* the annotation, without any fragments and not enclosed in specific resources
4040
*/
41-
public function getTargetResourceId();
41+
public function getTargetResourceId(): ?string;
4242

4343

4444
public function getOnSelector();

src/Iiif/Presentation/Common/Model/Resources/CanvasInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function getPossibleTextAnnotationContainers($motivation = null);
3939
* @param boolean $painting
4040
* @return LazyLoadingIterator
4141
*/
42-
public function getPotentialTextAnnotationContainerIterator($painting = null);
42+
public function getPotentialTextAnnotationContainerIterator($painting = null): ?LazyLoadingIterator;
4343

4444
/**
4545
* @return int

src/Iiif/Presentation/Common/Model/Resources/IiifResourceInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ public function getRenderingUrlsForFormat($format, $useChildResources = true);
173173
* @return string A thumbnail URL for the resource, either provided by a "thumbnail" property or
174174
* generated with default dimensions in @link \Ubl\Iiif\Tools\Options.
175175
*/
176-
public function getThumbnailUrl();
176+
public function getThumbnailUrl(): ?string;
177177

178178
/**
179179
* Extract data from json node by JsonPath expression

src/Iiif/Presentation/Common/Model/Resources/ManifestInterface.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@
2020

2121
namespace Ubl\Iiif\Presentation\Common\Model\Resources;
2222

23+
use Ubl\Iiif\Presentation\Common\Model\AbstractIiifEntity;
24+
2325
interface ManifestInterface extends IiifResourceInterface {
2426

2527
/**
2628
* versions 1, 2: canvases of default sequence
2729
* version 3: items of the first range with "sequence" behaviour; otherwise items of manifest
28-
* @return CanvasInterface[]
30+
* @return ?CanvasInterface[]
2931
*/
30-
public function getDefaultCanvases();
32+
public function getDefaultCanvases(): ?array;
3133

3234
/**
3335
* version 2: first range marked as top or any ranges that are no children of other ranges
@@ -58,7 +60,7 @@ public function getStructures();
5860
* @return IiifResourceInterface The PHP object representation of the IIIF resource the ID $id.
5961
* If the manifest does not contain such a resource, return null.
6062
*/
61-
public function getContainedResourceById($id);
63+
public function getContainedResourceById($id): ?AbstractIiifEntity;
6264

6365
}
6466

src/Iiif/Presentation/V1/Model/Resources/AbstractIiifResource1.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,6 @@
3131

3232
abstract class AbstractIiifResource1 extends AbstractIiifResource implements IiifResourceInterface {
3333

34-
/**
35-
*
36-
* @var string
37-
*/
38-
protected $id;
3934
/**
4035
*
4136
* @var string
@@ -319,11 +314,13 @@ public function getSummaryForDisplay($language = null, $joinChars = "; ", $optio
319314
* {@inheritDoc}
320315
* @see \Ubl\Iiif\Presentation\Common\Model\Resources\IiifResourceInterface::getThumbnailUrl()
321316
*/
322-
public function getThumbnailUrl() {
317+
public function getThumbnailUrl(): ?string
318+
{
323319
return null;
324320
}
325321

326-
protected function getValueForDisplay($value, $language = null, $joinChars = "; ", $options = IiifResourceInterface::SANITIZE_XML_ENCODE_NONHTML) {
322+
protected function getValueForDisplay($value, $language = null, $joinChars = "; ", $options = IiifResourceInterface::SANITIZE_XML_ENCODE_NONHTML): string|array|null
323+
{
327324
if (is_null($value)){
328325
return null;
329326
}

0 commit comments

Comments
 (0)