Passed
Pull Request — master (#247)
by Théo
02:40
created

Placeholder   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
dl 0
loc 23
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A compact() 0 6 1
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 Assert\Assertion;
18
use KevinGH\Box\Compactor;
19
20
final class Placeholder implements Compactor
21
{
22
    private $placeholders;
23
24
    /**
25
     * @param scalar[] $placeholders
26
     */
27
    public function __construct(array $placeholders)
28
    {
29
        Assertion::allScalar($placeholders);
30
31
        $this->placeholders = $placeholders;
32
    }
33
34
    /**
35
     * {@inheritdoc}
36
     */
37
    public function compact(string $file, string $contents): string
38
    {
39
        return str_replace(
40
            array_keys($this->placeholders),
41
            array_values($this->placeholders),
42
            $contents
43
        );
44
    }
45
}
46