Npm   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 61
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 61
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setDestination() 0 7 2
A writeRc() 0 8 2
1
<?php
2
3
/*
4
 * Composer plugin for bower/npm assets
5
 *
6
 * @link      https://github.com/hiqdev/composer-asset-plugin
7
 * @package   composer-asset-plugin
8
 * @license   BSD-3-Clause
9
 * @copyright Copyright (c) 2015-2016, HiQDev (http://hiqdev.com/)
10
 */
11
12
namespace hiqdev\composerassetplugin;
13
14
/**
15
 * NPM package manager class.
16
 *
17
 * @author Andrii Vasyliev <[email protected]>
18
 */
19
class Npm extends PackageManager
20
{
21
    /**
22
     * {@inheritdoc}
23
     */
24
    protected $name = 'npm';
25
26
    /**
27
     * {@inheritdoc}
28
     */
29
    public $file = 'package.json';
30
31
    /**
32
     * {@inheritdoc}
33
     */
34
    public $rcfile = '.npmrc';
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public $phpPackage = 'non existent npmphp';
40
41
    public $args = [];
42
43
    /**
44
     * {@inheritdoc}
45
     * Not really sure if peer, bundled and optional dependencies are really needed.
46
     * Remove them if not.
47
     */
48
    protected $dependencies = [
49
        'dependencies', 'devDependencies',
50
        'peerDependencies', 'bundledDependencies', 'optionalDependencies',
51
    ];
52
53
    /**
54
     * @var array Minimal NPM config
55
     */
56
    protected $config = [
57
        'name'        => 'composer-asset-plugin',
58
        'description' => "This file is auto-generated with 'hiqdev/composer-asset-plugin'.",
59
        'readme'      => ' ',
60
        'repository'  => ['type' => 'git'],
61
    ];
62
63
    public function setDestination($dir)
64
    {
65
        if (substr($dir, 0, 7) === 'vendor/') {
66
            $dir = substr($dir, 7);
67
        }
68
        $this->rc['prefix'] = $dir;
69
    }
70
71
    public function writeRc($path, $data)
72
    {
73
        $str = '';
74
        foreach ($data as $key => $value) {
75
            $str .= "$key = $value\n";
76
        }
77
        file_put_contents($path, $str);
78
    }
79
}
80