Bitbucket   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A getFileContents() 11 11 1
A parseJson() 9 9 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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\RepositoryManager;
13
14
use AppBundle\Entity\Project;
15
16 View Code Duplication
class Bitbucket implements RepositoryManager
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
17
{
18
    /**
19
     * @var \Bitbucket\API\Repositories\Src
20
     */
21
    private $client;
22
23
    /**
24
     * Constructor.
25
     */
26
    public function __construct()
27
    {
28
        $this->client = new \Bitbucket\API\Repositories\Src();
29
        //$this->client ->setCredentials( new Bitbucket\API\Authentication\Basic($bb_user, $bb_pass) );
0 ignored issues
show
Unused Code Comprehensibility introduced by
60% of this comment could be valid code. Did you maybe forget this after debugging?

Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.

The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.

This check looks for comments that seem to be mostly valid code and reports them.

Loading history...
30
    }
31
32
    /**
33
     * Get the file contents.
34
     *
35
     *
36
     * @param Project $project
37
     * @param string $file
38
     *
39
     * @return array
40
     */
41
    public function getFileContents(Project $project, string $file): array
42
    {
43
        $response = $this->client->raw(
44
            $project->getVendorName(),
45
            $project->getPackageName(),
46
            $project->getBranch(),
47
            $file
48
        );
49
50
        return $this->parseJson($response->getContent());
51
    }
52
53
    /**
54
     * Parse JSON data.
55
     *
56
     * @param string $data
57
     *
58
     * @return mixed
59
     */
60
    private function parseJson($data)
61
    {
62
        $parsedData = json_decode($data, true);
63
        if ($parsedData === false) {
64
            throw new \RuntimeException('Unable to parse json file');
65
        }
66
67
        return $parsedData;
68
    }
69
}
70