Issues (182)

src/Annotation/Link.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
namespace BEAR\Resource\Annotation;
6
7
use Attribute;
8
use Doctrine\Common\Annotations\Annotation\NamedArgumentConstructor;
0 ignored issues
show
The type Doctrine\Common\Annotati...amedArgumentConstructor was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use JsonSerializable;
10
use Override;
11
12
/**
13
 * @Annotation
14
 * @Target("METHOD")
15
 * @NamedArgumentConstructor
16
 */
17
#[Attribute(Attribute::TARGET_METHOD | Attribute::IS_REPEATABLE)]
18
final class Link implements JsonSerializable
19
{
20
    /**
21
     * Relation to the target resource of the link
22
     *
23
     * @var string
24
     */
25
    public $rel;
26
27
    /**
28
     * A URI template, as defined by RFC 6570
29
     *
30
     * @var string
31
     */
32
    public $href;
33
34
    /**
35
     * A method for the Link
36
     *
37
     * @var string
38
     * @Enum({"get", "post", "put", "patch", "delete"})
39
     */
40
    public $method;
41
42
    /**
43
     * A title for the link
44
     *
45
     * @var string
46
     */
47
    public $title;
48
49
    /**
50
     * Crawl tag ID for crawl request
51
     *
52
     * @var string
53
     */
54
    public $crawl;
55
56
    /**
57
     * @return string[]
58
     * @psalm-return array{rel: string, href: string, method: string, title?: string}
59
     */
60
    #[Override]
61
    public function jsonSerialize(): array
62
    {
63
        $json = [
64
            'rel' => $this->rel,
65
            'href' => $this->href,
66
            'method' => $this->method,
67
        ];
68
        if ($this->title) {
69
            $json += ['title' => $this->title];
70
        }
71
72
        return $json;
73
    }
74
75
    /** @param array{rel?: string, href?: string, method?: string, title?: string, crawl?:string} $values */
76
    public function __construct(
77
        array $values = [],
78
        string $rel = '',
79
        string $href = '',
80
        string $method = 'get',
81
        string $title = '',
82
        string $crawl = '',
83
    ) {
84
        $this->rel = $values['rel'] ?? $rel;
85
        $this->href = $values['href'] ?? $href;
86
        $this->method = $values['method'] ?? $method;
87
        $this->title = $values['title'] ?? $title;
88
        $this->crawl = $values['crawl'] ?? $crawl;
89
    }
90
}
91