Issues (31)

src/Pohoda/Common/AddParameterTrait.php (1 issue)

1
<?php
2
3
/**
4
 * This file is part of riesenia/pohoda package.
5
 *
6
 * Licensed under the MIT License
7
 * (c) RIESENIA.com
8
 */
9
10
declare(strict_types=1);
11
12
namespace Riesenia\Pohoda\Common;
13
14
use Riesenia\Pohoda\Type\Parameter;
15
16
/**
17
 * @property array{
18
 *     parameters?: iterable<Parameter>
19
 * } $data
20
 */
21
trait AddParameterTrait
22
{
23
    /**
24
     * Set user-defined parameter.
25
     *
26
     * @param string     $name  (can be set without preceding VPr / RefVPr)
27
     * @param string     $type
28
     * @param mixed      $value
29
     * @param mixed|null $list
30
     * @return self
31
     */
32 15
    public function addParameter(string $name, string $type, mixed $value, mixed $list = null): self
33
    {
34 15
        if (!isset($this->data['parameters'])
35 15
            || !(
36 15
                is_array($this->data['parameters'])
37 15
                || (is_a($this->data['parameters'], \ArrayAccess::class))
38 15
            )
39
        ) {
40 15
            $this->data['parameters'] = [];
0 ignored issues
show
Bug Best Practice introduced by
The property data does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
41
        }
42
43 15
        $parameter = new Parameter(
44 15
            $this->namespacesPaths,
45 15
            $this->sanitizeEncoding,
46 15
            $this->normalizerFactory,
47 15
        );
48 15
        $parameter
49 15
            ->setDirectionalVariable($this->useOneDirectionalVariables)
50 15
            ->setResolveOptions($this->resolveOptions)
51 15
            ->setData([
52 15
                'name' => $name,
53 15
                'type' => $type,
54 15
                'value' => $value,
55 15
                'list' => $list,
56 15
            ]);
57 15
        $this->data['parameters'][] = $parameter;
58
59 15
        return $this;
60
    }
61
}
62