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.

Manager   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 97
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 23
dl 0
loc 97
c 1
b 0
f 0
rs 10
ccs 0
cts 40
cp 0
wmc 9

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getManifest() 0 3 1
A getRunningFile() 0 7 2
A setRunningFile() 0 10 2
A __construct() 0 3 1
A update() 0 18 3
1
<?php
2
3
namespace Deployer\Component\PharUpdate;
4
5
use Deployer\Component\PharUpdate\Exception\InvalidArgumentException;
6
use Deployer\Component\PharUpdate\Version\Parser;
7
use Deployer\Component\PharUpdate\Version\Version;
8
9
/**
10
 * Manages the Phar update process.
11
 *
12
 * @author Kevin Herrera <[email protected]>
13
 */
14
class Manager
15
{
16
    /**
17
     * The update manifest.
18
     *
19
     * @var Manifest
20
     */
21
    private $manifest;
22
23
    /**
24
     * The running file (the Phar that will be updated).
25
     *
26
     * @var string
27
     */
28
    private $runningFile;
29
30
    /**
31
     * Sets the update manifest.
32
     *
33
     * @param Manifest $manifest The manifest.
34
     */
35
    public function __construct(Manifest $manifest)
36
    {
37
        $this->manifest = $manifest;
38
    }
39
40
    /**
41
     * Returns the manifest.
42
     *
43
     * @return Manifest The manifest.
44
     */
45
    public function getManifest()
46
    {
47
        return $this->manifest;
48
    }
49
50
    /**
51
     * Returns the running file (the Phar that will be updated).
52
     *
53
     * @return string The file.
54
     */
55
    public function getRunningFile()
56
    {
57
        if (null === $this->runningFile) {
58
            $this->runningFile = realpath($_SERVER['argv'][0]);
59
        }
60
61
        return $this->runningFile;
62
    }
63
64
    /**
65
     * Sets the running file (the Phar that will be updated).
66
     *
67
     * @param string $file The file name or path.
68
     *
69
     * @throws Exception\Exception
70
     * @throws InvalidArgumentException If the file path is invalid.
71
     */
72
    public function setRunningFile($file)
73
    {
74
        if (false === is_file($file)) {
75
            throw InvalidArgumentException::create(
76
                'The file "%s" is not a file or it does not exist.',
77
                $file
78
            );
79
        }
80
81
        $this->runningFile = $file;
82
    }
83
84
    /**
85
     * Updates the running Phar if any is available.
86
     *
87
     * @param string|Version $version  The current version.
88
     * @param boolean        $major    Lock to current major version?
89
     * @param boolean        $pre      Allow pre-releases?
90
     *
91
     * @return boolean TRUE if an update was performed, FALSE if none available.
92
     */
93
    public function update($version, $major = false, $pre = false)
94
    {
95
        if (false === ($version instanceof Version)) {
96
            $version = Parser::toVersion($version);
97
        }
98
99
        if (null !== ($update = $this->manifest->findRecent(
100
            $version,
101
            $major,
102
            $pre
103
        ))) {
104
            $update->getFile();
105
            $update->copyTo($this->getRunningFile());
106
107
            return true;
108
        }
109
110
        return false;
111
    }
112
}
113