CakePHPInstaller   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 8

3 Methods

Rating   Name   Duplication   Size   Complexity  
A inflectPackageVars() 0 15 3
A getLocations() 0 6 2
A matchesCakeVersion() 0 13 3
1
<?php
2
namespace Composer\Installers;
3
4
use Composer\DependencyResolver\Pool;
5
use Composer\Semver\Constraint\Constraint;
6
7
class CakePHPInstaller extends BaseInstaller
8
{
9
    protected $locations = array(
10
        'plugin' => 'Plugin/{$name}/',
11
    );
12
13
    /**
14
     * Format package name to CamelCase
15
     */
16
    public function inflectPackageVars($vars)
17
    {
18
        if ($this->matchesCakeVersion('>=', '3.0.0')) {
19
            return $vars;
20
        }
21
22
        $nameParts = explode('/', $vars['name']);
23
        foreach ($nameParts as &$value) {
24
            $value = strtolower(preg_replace('/(?<=\\w)([A-Z])/', '_\\1', $value));
25
            $value = str_replace(array('-', '_'), ' ', $value);
26
            $value = str_replace(' ', '', ucwords($value));
27
        }
28
        $vars['name'] = implode('/', $nameParts);
29
30
        return $vars;
31
    }
32
33
    /**
34
     * Change the default plugin location when cakephp >= 3.0
35
     */
36
    public function getLocations()
37
    {
38
        if ($this->matchesCakeVersion('>=', '3.0.0')) {
39
            $this->locations['plugin'] =  $this->composer->getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/';
0 ignored issues
show
Bug introduced by
The method getConfig() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

39
            $this->locations['plugin'] =  $this->composer->/** @scrutinizer ignore-call */ getConfig()->get('vendor-dir') . '/{$vendor}/{$name}/';

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
40
        }
41
        return $this->locations;
42
    }
43
44
    /**
45
     * Check if CakePHP version matches against a version
46
     *
47
     * @param string $matcher
48
     * @param string $version
49
     * @return bool
50
     * @phpstan-param Constraint::STR_OP_* $matcher
51
     */
52
    protected function matchesCakeVersion($matcher, $version)
53
    {
54
        $repositoryManager = $this->composer->getRepositoryManager();
55
        if (! $repositoryManager) {
56
            return false;
57
        }
58
59
        $repos = $repositoryManager->getLocalRepository();
60
        if (!$repos) {
61
            return false;
62
        }
63
64
        return $repos->findPackage('cakephp/cakephp', new Constraint($matcher, $version)) !== null;
65
    }
66
}
67