Issues (3641)

Component/SchemaItemsSpecificationComponent.php (1 issue)

1
<?php
2
3
/**
4
 * Copyright © 2016-present Spryker Systems GmbH. All rights reserved.
5
 * Use of this software requires acceptance of the Evaluation License Agreement. See LICENSE file.
6
 */
7
8
namespace Spryker\Zed\DocumentationGeneratorRestApi\Business\Renderer\Component;
9
10
use Generated\Shared\Transfer\SchemaItemsComponentTransfer;
11
12
/**
13
 * Specification:
14
 *  - This component describes a single Schema Object Property.
15
 *  - This component partly covers Schema Object Properties in OpenAPI specification format (see https://swagger.io/specification/#schemaObject).
16
 */
17
class SchemaItemsSpecificationComponent implements SchemaItemsSpecificationComponentInterface
18
{
19
    /**
20
     * @var string
21
     */
22
    protected const KEY_REF = '$ref';
23
24
    /**
25
     * @var string
26
     */
27
    protected const KEY_ITEMS = 'items';
28
29
    /**
30
     * @var string
31
     */
32
    protected const KEY_ONEOF = 'oneOf';
33
34
    /**
35
     * @var string
36
     */
37
    protected const KEY_TYPE = 'type';
38
39
    /**
40
     * @var string
41
     */
42
    protected const KEY_NULLABLE = 'nullable';
43
44
    /**
45
     * @var string
46
     */
47
    protected const VALUE_TYPE_ARRAY = 'array';
48
49
    /**
50
     * @var \Generated\Shared\Transfer\SchemaItemsComponentTransfer|null
51
     */
52
    protected $schemaItemsComponentTransfer;
53
54
    /**
55
     * @param \Generated\Shared\Transfer\SchemaItemsComponentTransfer $schemaItemsComponentTransfer
56
     *
57
     * @return void
58
     */
59
    public function setSchemaItemsComponentTransfer(SchemaItemsComponentTransfer $schemaItemsComponentTransfer): void
60
    {
61
        $this->schemaItemsComponentTransfer = $schemaItemsComponentTransfer;
62
    }
63
64
    /**
65
     * @return array
66
     */
67
    public function getSpecificationComponentData(): array
68
    {
69
        if (!$this->validateSchemaPropertyComponentTransfer()) {
70
            return [];
71
        }
72
73
        return $this->addOneOf();
74
    }
75
76
    /**
77
     * @return array
78
     */
79
    protected function addOneOf(): array
80
    {
81
        $schemaItems = [];
82
83
        if ($this->schemaItemsComponentTransfer->getOneOf()) {
0 ignored issues
show
The method getOneOf() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

83
        if ($this->schemaItemsComponentTransfer->/** @scrutinizer ignore-call */ getOneOf()) {

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
84
            foreach ($this->schemaItemsComponentTransfer->getOneOf() as $ref) {
85
                $schemaItems[static::KEY_ONEOF][][static::KEY_REF] = $ref;
86
            }
87
        }
88
89
        return $schemaItems;
90
    }
91
92
    /**
93
     * @return bool
94
     */
95
    protected function validateSchemaPropertyComponentTransfer(): bool
96
    {
97
        if (!$this->schemaItemsComponentTransfer) {
98
            return false;
99
        }
100
101
        $this->schemaItemsComponentTransfer->requireOneOf();
102
103
        return true;
104
    }
105
}
106