GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — 3.0 ( f7dde3...9c92ff )
by Vermeulen
02:27
created

Memcache::ifExists()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 3
eloc 7
c 0
b 0
f 0
nc 3
nop 1
dl 0
loc 13
rs 9.4285
1
<?php
2
3
namespace BFW\Traits;
4
5
trait Memcache
6
{
7
    /**
8
     * Permet de savoir si la clé existe
9
     * 
10
     * @param string $key la clé disignant les infos concernées
11
     * 
12
     * @throws \Exception Erreur dsans les paramètres donnée à la méthode
13
     * 
14
     * @return bool
15
     */
16
    public function ifExists($key)
17
    {
18
        $verifParams = verifTypeData([['type' => 'string', 'data' => $key]]);
19
        if (!$verifParams) {
20
            throw new \Exception('The $key parameters must be a string');
21
        }
22
23
        if ($this->get($key) === false) {
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
24
            return false;
25
        }
26
27
        return true;
28
    }
29
30
    /**
31
     * On modifie le temps avant expiration des infos sur
32
     * le serveur memcached pour une clé choisie.
33
     * 
34
     * @param string $key    la clé disignant les infos concerné
35
     * @param int    $expire le nouveau temps avant expiration
36
     *                          (0: pas d'expiration, max 30jours)
37
     * 
38
     * @throws \Exception Erreur dsans les paramètres donnée à la méthode
39
     * 
40
     * @return boolean|null
41
     */
42
    public function majExpire($key, $expire)
43
    {
44
        $verifParams = verifTypeData([
45
            ['type' => 'string', 'data' => $key],
46
            ['type' => 'int', 'data' => $expire]
47
        ]);
48
49
        if (!$verifParams) {
50
            throw new \Exception(
51
                'Once of parameters $key or $expire not have a correct type.'
52
            );
53
        }
54
55
        $value = $this->get($key); //Récupère la valeur
0 ignored issues
show
Bug introduced by
It seems like get() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
56
        
57
        //On la "modifie" en remettant la même valeur mais en changeant
58
        //le temps avant expiration
59
        $this->replace($key, $value, 0, $expire);
0 ignored issues
show
Bug introduced by
It seems like replace() must be provided by classes using this trait. How about adding it as abstract method to this trait?

This check looks for methods that are used by a trait but not required by it.

To illustrate, let’s look at the following code example

trait Idable {
    public function equalIds(Idable $other) {
        return $this->getId() === $other->getId();
    }
}

The trait Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
60
        
61
        return true;
62
    }
63
}
64