VKDataStorage   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 80
Duplicated Lines 13.75 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 12
c 2
b 1
f 0
lcom 0
cbo 1
dl 11
loc 80
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A set() 0 11 3
B getKeys() 0 11 5
A get() 11 11 3

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
2
3
namespace FreedomCore\VK\API;
4
5
6
use FreedomCore\VK\VKBase;
7
use FreedomCore\VK\VKException;
8
9
/**
10
 * Class VKDataStorage
11
 * @package FreedomCore\VK
12
 */
13
class VKDataStorage extends VKAPI {
14
15
    /**
16
     * API Method for this class
17
     * @var string
18
     */
19
    protected $apiMethod = 'storage.';
20
21
    /**
22
     * VKDataStorage constructor.
23
     * @param VKBase $vkObject
24
     */
25
    public function __construct(VKBase $vkObject) {
26
        parent::__construct($vkObject);
27
    }
28
29
    /**
30
     * Returns a value of variable with the name set by key parameter
31
     * @param string $storageKey
32
     * @param string $storageKeys
33
     * @param int $userID
34
     * @param int $isGlobal
35
     * @throws VKException
36
     * @return array
37
     */
38 View Code Duplication
    protected function get($storageKey, $storageKeys, $userID, $isGlobal) {
0 ignored issues
show
Duplication introduced by
This method 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...
39
        parent::isAllowed();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (isAllowed() instead of get()). Are you sure this is correct? If so, you might want to change this to $this->isAllowed().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
40
        $requestParameters = [
41
            'key'       =>  substr($storageKey, 0, 100),
42
            'keys'      =>  $storageKeys,
43
            'user_id'   =>  $userID,
44
            'global'    =>  ($isGlobal > 1 || $isGlobal < 0) ? 0 : $isGlobal
45
46
        ];
47
        return parent::executeQuery(__FUNCTION__, $requestParameters);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeQuery() instead of get()). Are you sure this is correct? If so, you might want to change this to $this->executeQuery().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
48
    }
49
50
    /**
51
     * Saves a value of variable with the name set by key parameter
52
     * @param string $storageKey
53
     * @param string $keyValue
54
     * @param int $userID
55
     * @param int $isGlobal
56
     * @throws VKException
57
     * @return array
58
     */
59
    protected function set($storageKey, $keyValue, $userID, $isGlobal) {
60
        parent::isAllowed();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (isAllowed() instead of set()). Are you sure this is correct? If so, you might want to change this to $this->isAllowed().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
61
        $requestParameters = [
62
            'key'       =>  substr($storageKey, 0, 100),
63
            'value'     =>  $keyValue,
64
            'user_id'   =>  $userID,
65
            'global'    =>  ($isGlobal > 1 || $isGlobal < 0) ? 0 : $isGlobal
66
67
        ];
68
        return parent::executeQuery(__FUNCTION__, $requestParameters);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeQuery() instead of set()). Are you sure this is correct? If so, you might want to change this to $this->executeQuery().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
69
    }
70
71
    /**
72
     * Returns the names of all variables
73
     * @param int $userID
74
     * @param int $isGlobal
75
     * @param int $setOffset
76
     * @param int $returnResult
77
     * @throws VKException
78
     * @return array
79
     */
80
    protected function getKeys($userID, $isGlobal, $setOffset = 0, $returnResult = 100) {
81
        parent::isAllowed();
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (isAllowed() instead of getKeys()). Are you sure this is correct? If so, you might want to change this to $this->isAllowed().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
82
        $requestParameters = [
83
            'user_id'   =>  $userID,
84
            'global'    =>  ($isGlobal > 1 || $isGlobal < 0) ? 0 : $isGlobal,
85
            'offset'    =>  $setOffset,
86
            'count'     =>  ($returnResult > 1000 || $returnResult < 0) ? 100 : $returnResult,
87
88
        ];
89
        return parent::executeQuery(__FUNCTION__, $requestParameters);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (executeQuery() instead of getKeys()). Are you sure this is correct? If so, you might want to change this to $this->executeQuery().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
90
    }
91
92
}