Completed
Push — master ( 83fca8...0d9c6e )
by Andrii
10:43
created

src/jsonApi/AttributionBasedCollectionDocument.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
declare(strict_types=1);
3
4
namespace hiapi\jsonApi;
5
6
use WoohooLabs\Yin\JsonApi\Schema\Document\AbstractCollectionDocument;
7
use WoohooLabs\Yin\JsonApi\Schema\JsonApiObject;
8
use WoohooLabs\Yin\JsonApi\Schema\Link\DocumentLinks;
9
use hiapi\jsonApi\ResourceFactoryInterface;
10
11
/**
12
 * Allows easy creation of JSON:API collection documents class.
13
 * `attributionClass` can be provided or it will be found automatically
14
 * by class name in the same directory, see `findAttributionClass`.
15
 *
16
 * @author Andrii Vasyliev <[email protected]>
17
 */
18
class AttributionBasedCollectionDocument extends AbstractCollectionDocument
19
{
20
    protected string $attributionClass;
0 ignored issues
show
This code did not parse for me. Apparently, there is an error somewhere around this line:

Syntax error, unexpected T_STRING, expecting T_FUNCTION or T_CONST
Loading history...
21
22
    public function __construct(ResourceFactoryInterface $resourceFactory)
23
    {
24
        parent::__construct($resourceFactory->getFor($this->getAttributionClass()));
25
    }
26
27
    public function getAttributionClass(): string
28
    {
29
        if (empty($this->attributionClass)) {
30
            $this->attributionClass = $this->findAttributionClass();
31
        }
32
33
        return $this->attributionClass;
34
    }
35
36
    private function findAttributionClass(): string
37
    {
38
        return substr(get_class($this), 0, -19) . 'Attribution';
39
    }
40
41
    public function getJsonApi(): ?JsonApiObject
42
    {
43
        return new JsonApiObject('1.1');
44
    }
45
46
    public function getMeta(): array
47
    {
48
        return [];
49
    }
50
51
    public function getLinks(): ?DocumentLinks
52
    {
53
        return null;
54
    }
55
}
56