Issues (39)

src/Context/Context.php (2 issues)

1
<?php
2
3
namespace Bdf\Serializer\Context;
4
5
use Bdf\Serializer\Normalizer\NormalizerInterface;
6
7
/**
8
 * Context
9
 */
10
abstract class Context
11
{
12
    /**
13
     * The context options
14
     *
15
     * @var array
16
     */
17
    protected $options;
18
19
    /**
20
     * The normalizer
21
     *
22
     * @var NormalizerInterface
23
     */
24
    protected $normalizer;
25
26
    /**
27
     * Context constructor.
28
     *
29
     * @param NormalizerInterface $normalizer
30
     * @param array $options
31
     */
32 256
    public function __construct(NormalizerInterface $normalizer, array $options = [])
33
    {
34 256
        $this->normalizer = $normalizer;
35 256
        $this->options = $options;
36
    }
37
38
    /**
39
     * Get the root normalizer
40
     *
41
     * @return NormalizerInterface
42
     */
43 166
    public function root(): NormalizerInterface
44
    {
45 166
        return $this->normalizer;
46
    }
47
48
    /**
49
     * Get an option
50
     *
51
     * @param string $key
52
     * @param T $default
0 ignored issues
show
The type Bdf\Serializer\Context\T 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...
53
     *
54
     * @return (T is null ? mixed|null : T)
0 ignored issues
show
Documentation Bug introduced by
The doc comment (T at position 1 could not be parsed: Expected ')' at position 1, but found 'T'.
Loading history...
55
     *
56
     * @template T
57
     */
58 86
    public function option(string $key, $default = null)
59
    {
60 86
        return isset($this->options[$key]) ? $this->options[$key] : $default;
61
    }
62
63
    /**
64
     * Create new context from this one
65
     *
66
     * @param array $newOptions
67
     *
68
     * @return static
69
     */
70 158
    public function duplicate(array $newOptions = null): self
71
    {
72 158
        if ($newOptions === null) {
73 154
            return $this;
74
        }
75
76 18
        $context = clone $this;
77 18
        $context->prepareOptions($newOptions);
78
79 18
        return $context;
80
    }
81
82
    /**
83
     * Prepare the known options
84
     *
85
     * @param array $options
86
     */
87
    abstract protected function prepareOptions(array $options): void;
88
}
89