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

FileParser   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 1
dl 0
loc 43
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B parse() 0 30 6
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