GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( 99078a...9605c1 )
by Oanh
02:49
created

FileResourceTemplate::getParametersForReplace()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
ccs 0
cts 2
cp 0
cc 1
eloc 2
nc 1
nop 0
crap 2
1
<?php
2
/* (c) Anton Medvedev <[email protected]>
3
 *
4
 * For the full copyright and license information, please view the LICENSE
5
 * file that was distributed with this source code.
6
 */
7
8
namespace Deployer\Initializer\Template;
9
10
use Deployer\Initializer\Exception\ResourceNotFoundException;
11
12
/**
13
 * Abstract template for use file resource for create deployer configuration
14
 *
15
 * @author Vitaliy Zhuk <[email protected]>
16
 */
17
abstract class FileResourceTemplate implements TemplateInterface
18
{
19
    /**
20
     * {@inheritDoc}
21
     */
22 2
    public function initialize($filePath)
23
    {
24 2
        $resourcePath = $this->getFilePathOfResource();
25
26 2
        if (!file_exists($resourcePath) || !is_file($resourcePath)) {
27 1
            throw new ResourceNotFoundException(sprintf(
28 1
                'Not found resource file "%s".',
29
                $resourcePath
30 1
            ));
31
        }
32
33 1
        if (!is_readable($resourcePath)) {
34
            throw new \RuntimeException(sprintf(
35
                'The resource file "%s" not readable.',
36
                $resourcePath
37
            ));
38
        }
39
40 1
        $resource = file_get_contents($resourcePath);
41
42 1
        $parameters = $this->getParametersForReplace();
43 1
        $replaceParameters = [];
44
45 1
        array_walk($parameters, function ($value, $key) use (&$replaceParameters) {
46 1
            $replaceParameters['%' . $key . '%'] = $value;
47 1
        });
48
49 1
        $resource = strtr($resource, $replaceParameters);
50
51 1
        file_put_contents($filePath, $resource);
52 1
    }
53
54
    /**
55
     * Get file path of resource
56
     *
57
     * @return string
58
     */
59
    abstract protected function getFilePathOfResource();
60
61
    /**
62
     * Get parameters for replace in resource
63
     *
64
     * @return array
65
     */
66
    protected function getParametersForReplace()
67
    {
68
        return [];
69
    }
70
}
71