Failed Conditions
Push — master ( 6a9a20...351c71 )
by Mickael
01:43
created

FileParser::parse()   B

Complexity

Conditions 6
Paths 5

Size

Total Lines 30

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.8177
c 0
b 0
f 0
cc 6
nc 5
nop 1
1
<?php
2
3
/**
4
 * Author: mickael Louzet @micklouzet
5
 * File: RegistrationController.php
6
 * Created: 05/12/2019
7
 */
8
9
declare(strict_types=1);
10
11
namespace Louzet\ComposerLockFileParser;
12
13
use Louzet\ComposerLockFileParser\ParserCollection;
14
15
class FileParser implements FileParserInterface
0 ignored issues
show
Coding Style introduced by
FileParser does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
16
{
17
    /**
18
     * {@inheritDoc}
19
     */
20
    public static function parse(string $filePath): ParserCollection
21
    {
22
        if (!\is_file($filePath)) {
23
            return [];
24
        }
25
26
        if (!$json = \file_get_contents($filePath)) {
27
            return [];
28
        }
29
30
        $data = \json_decode($json, true);
31
32
        $components = [];
33
34
        if (!$data || !isset($data['packages'])) {
35
            return [];
36
        }
37
        foreach ($data['packages'] as $package) {
38
            $components[] = [
39
                'name' => $package['name'],
40
                'version' => $package['version'],
41
                'source' => $package['source'],
42
                'require' => $package['require'] ?? [],
43
                'description' => $package['description'],
44
                'keywords' => $package['keywords'],
45
                'time' => $package['time'],
46
            ];
47
        }
48
        return new ParserCollection($components);
49
    }
50
51
    // public function byVendor(string $vendor)
52
    // {
53
    //     if (0 !== \strpos($package['name'], "vendor/")) {
54
    //         continue;
55
    //     }
56
    // }
57
}
58