Issues (224)

src/Compactor/Placeholder.php (1 issue)

Labels
Severity
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the box project.
7
 *
8
 * (c) Kevin Herrera <[email protected]>
9
 *     Théo Fidry <[email protected]>
10
 *
11
 * This source file is subject to the MIT license that is bundled
12
 * with this source code in the file LICENSE.
13
 */
14
15
namespace KevinGH\Box\Compactor;
16
17
use Webmozart\Assert\Assert;
18
use function array_keys;
19
use function str_replace;
20
21
final class Placeholder implements Compactor
22
{
23
    /**
24
     * @var scalar[]
25
     */
26
    private readonly array $placeholders;
27
28
    /**
29
     * @param scalar[] $placeholders
30
     */
31
    public function __construct(array $placeholders)
32
    {
33
        Assert::allScalar($placeholders);
34
35
        $this->placeholders = $placeholders;
0 ignored issues
show
The property placeholders is declared read-only in KevinGH\Box\Compactor\Placeholder.
Loading history...
36
    }
37
38
    public function compact(string $file, string $contents): string
39
    {
40
        return str_replace(
41
            array_keys($this->placeholders),
42
            $this->placeholders,
43
            $contents,
44
        );
45
    }
46
}
47