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.

Locker::writeToLockFile()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 9
rs 9.6666
cc 1
eloc 5
nc 1
nop 0
1
<?php
2
namespace SeleniumSetup\Locker;
3
4
use SeleniumSetup\FileSystem;
5
use SeleniumSetup\SeleniumSetup;
6
7
class Locker
8
{
9
    protected $fileSystem;
10
    /**
11
     * @var ServerItem[]
12
     */
13
    protected $locker = [];
14
15
    public function __construct()
16
    {
17
        $this->fileSystem = new FileSystem();
18
    }
19
20
    public function openLockFile()
21
    {
22
        if (!$this->fileSystem->isFile(SeleniumSetup::$APP_ROOT_PATH . DIRECTORY_SEPARATOR . SeleniumSetup::DEFAULT_LOCK_FILENAME)) {
23
            return false;
24
        }
25
26
        $contents = $this->fileSystem->readFile(SeleniumSetup::$APP_ROOT_PATH . DIRECTORY_SEPARATOR . SeleniumSetup::DEFAULT_LOCK_FILENAME);
27
        $lockerRaw = json_decode($contents);
28
        foreach ($lockerRaw as $serverObj) {
29
            $this->addServer(ServerItemFactory::createFromObj($serverObj));
30
        }
31
        return true;
32
    }
33
34
    public function writeToLockFile()
35
    {   
36
        $this->fileSystem->writeToFile(
37
            SeleniumSetup::$APP_ROOT_PATH . DIRECTORY_SEPARATOR . SeleniumSetup::DEFAULT_LOCK_FILENAME,
38
            $this->toJson()
39
        );
40
        
41
        return true;
42
    }
43
44
    public function getServer($name)
45
    {
46
        if (!isset($this->locker[$name])) {
47
            throw new \Exception('Unknown server.');
48
        }
49
50
        return $this->locker[$name];
51
    }
52
53
    public function getServers()
54
    {
55
        return $this->locker;
56
    }
57
58
    public function addServer(ServerItem $server)
59
    {
60
        $this->locker[$server->getName()] = $server;
61
    }
62
    
63
    public function emptyLocker()
64
    {
65
        $this->locker = [];
66
    }
67
    
68 View Code Duplication
    public function toArray()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
69
    {
70
        $result = [];
71
        foreach ($this->locker as $server) {
72
            $result[$server->getName()] = $server->toArray();
73
        }
74
        return $result;
75
    }
76
    
77 View Code Duplication
    public function toJson()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
78
    {
79
        $result = [];
80
        foreach ($this->locker as $server) {
81
            $result[$server->getName()] = $server->toArray();
82
        }
83
        
84
        return json_encode($result, JSON_PRETTY_PRINT);
85
    }
86
87
}