LockerManager   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 7
eloc 18
dl 0
loc 55
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A writeLockData() 0 9 2
A __construct() 0 4 1
A readLockData() 0 9 2
A getLockFile() 0 12 2
1
<?php
2
/**
3
 * Copyright © Vaimo Group. All rights reserved.
4
 * See LICENSE_VAIMO.txt for license details.
5
 */
6
namespace Vaimo\ComposerPatches\Managers;
7
8
class LockerManager
9
{
10
    /**
11
     * @var \Composer\IO\IOInterface
12
     */
13
    private $appIO;
14
15
    /**
16
     * @param \Composer\IO\IOInterface $appIO
17
     */
18
    public function __construct(
19
        \Composer\IO\IOInterface $appIO
20
    ) {
21
        $this->appIO = $appIO;
22
    }
23
24
    public function readLockData()
25
    {
26
        $lockFile = $this->getLockFile();
27
28
        if (!$lockFile->exists()) {
29
            return null;
30
        }
31
32
        return $lockFile->read();
33
    }
34
35
    public function writeLockData(array $lock)
36
    {
37
        $lockFile = $this->getLockFile();
38
39
        if (!$lockFile->exists()) {
40
            return;
41
        }
42
43
        $lockFile->write($lock);
44
    }
45
46
    /**
47
     * @SuppressWarnings(PHPMD.StaticAccess)
48
     *
49
     * @return \Composer\Json\JsonFile
50
     */
51
    private function getLockFile()
52
    {
53
        $composerFile = \Composer\Factory::getComposerFile();
54
55
        $configExtension = 'json';
56
        $lockExtension = 'lock';
57
58
        $lockFile = $configExtension === pathinfo($composerFile, PATHINFO_EXTENSION)
59
            ? substr($composerFile, 0, -4) . $lockExtension
60
            : sprintf('%s.%s', $composerFile, $lockExtension);
61
62
        return new \Composer\Json\JsonFile($lockFile, null, $this->appIO);
63
    }
64
}
65