Code

< 40 %
40-60 %
> 60 %
1
<?php
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 */
11
12
namespace Koded\Stdlib;
13
14
use Countable;
15
use IteratorAggregate;
16
use JsonSerializable;
17
18
/**
19
 * Arguments is a MUTABLE, multipurpose class that encapsulates data.
20
 * It is useful for passing it around as a DTO.
21
 *
22
 * TIP: Avoid creating a child classes with properties from this one.
23
 * It will mess up your Zen.
24
 */
25
26
#[\AllowDynamicProperties]
27
class Arguments implements Argument,
28
                           TransformsToImmutable,
29
                           NamespaceDataFilter,
30
                           IteratorAggregate,
31
                           Countable,
32
                           JsonSerializable
33
{
34
    use AccessorTrait, MutatorTrait, ArrayDataFilterTrait {
35
        MutatorTrait::__set insteadof AccessorTrait;
36
    }
37
38 53
    public function __construct(protected array $data = []) {}
39
40
    public function __clone() {}
41
42 2
    public function namespace(
43
        string $prefix,
44
        bool $lowercase = true,
45
        bool $trim = true): static
46
    {
47 2
        return new static(
48 2
            $this->filter($this->toArray(), $prefix, $lowercase, $trim)
49 2
        );
50
    }
51
52 1
    public function toImmutable(): Immutable
53
    {
54 1
        return new Immutable($this->data);
55
    }
56
}
57