Pip::getName()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php declare(strict_types=1);
2
3
/**
4
 * This file is part of Packy.
5
 *
6
 * (c) Peter Nijssen
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace AppBundle\DependencyManager;
13
14
use AppBundle\Entity\Project;
15
use AppBundle\RepositoryManager\RepositoryManager;
16
17
class Pip implements DependencyManager
18
{
19
    /**
20
     * @var string
21
     */
22
    private $packageFileName;
23
24
    /**
25
     * Constructor.
26
     */
27
    public function __construct()
28
    {
29
        $this->packageFileName = 'requirements.txt';
30
    }
31
32
    /**
33
     * Fetch the dependencies.
34
     *
35
     * @param RepositoryManager $repositoryManager
36
     * @param Project           $project
37
     *
38
     * @return array
39
     */
40
    public function fetchDependencies(RepositoryManager $repositoryManager, Project $project): array
41
    {
42
        $fileContent = $repositoryManager->getFileContents($project, $this->packageFileName);
43
44
        if (is_array($fileContent) && !empty($fileContent)) {
45
            $lines = explode("\n", $fileContent);
46
47
            $dependencies = [];
48
            foreach ($lines as $line) {
49
                $chunks = explode('==', $line);
50
                if (count($chunks) == 2) {
51
                    $dependencies[$chunks[0]] = $chunks[1];
52
                }
53
            }
54
55
            return $dependencies;
56
        }
57
58
        return [];
59
    }
60
61
    /**
62
     * Get the name of the fetcher.
63
     *
64
     * @return string
65
     */
66
    public function getName(): string
67
    {
68
        return 'pip';
69
    }
70
}
71