Completed
Pull Request — master (#2)
by Angel
03:03
created

TesterTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 54
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A storeToken() 0 4 1
A amAuthByToken() 0 4 1
A seePaginationHttpHeaders() 0 7 1
A seeContentTypeHttpHeader() 0 5 1
1
<?php
2
3
namespace roaresearch\yii2\roa\test;
4
5
trait TesterTrait
6
{
7
    /**
8
     * @var string[] pairs of user_name => oauth2_token for oauth2 auth.
9
     */
10
    protected static $tokens = [];
11
12
    /**
13
     * @var string identificator for the auth/logged user.
14
     */
15
    protected $loggedUsername;
16
17
    /**
18
     * Saves a token and user by an unique name.
19
     *
20
     * @param string $tokenName unique name to index the tokens and models
21
     * @param string $token oauth2 authorization token
22
     * @param UserIdentity $user
0 ignored issues
show
Bug introduced by
There is no parameter named $user. Was it maybe removed?

This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.

Consider the following example. The parameter $italy is not defined by the method finale(...).

/**
 * @param array $germany
 * @param array $island
 * @param array $italy
 */
function finale($germany, $island) {
    return "2:1";
}

The most likely cause is that the parameter was removed, but the annotation was not.

Loading history...
23
     */
24
    public function storeToken($tokenName, $token)
25
    {
26
        static::$tokens[$tokenName] = $token;
27
    }
28
29
    /**
30
     * Authenticates a user stored in `$tokens`
31
     *
32
     * @param string $tokenName
33
     */
34
    public function amAuthByToken($tokenName)
35
    {
36
        $this->amBearerAuthenticated(static::$tokens[$tokenName]);
0 ignored issues
show
Bug introduced by
It seems like amBearerAuthenticated() 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...
37
    }
38
39
    /**
40
     * Checks over the HTTP pagination headers and (optionally) its values.
41
     */
42
    public function seePaginationHttpHeaders()
43
    {
44
        $this->seeHttpHeaderOnce('X-Pagination-Total-Count');
0 ignored issues
show
Bug introduced by
It seems like seeHttpHeaderOnce() 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...
45
        $this->seeHttpHeaderOnce('X-Pagination-Page-Count');
0 ignored issues
show
Bug introduced by
It seems like seeHttpHeaderOnce() 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...
46
        $this->seeHttpHeaderOnce('X-Pagination-Current-Page');
0 ignored issues
show
Bug introduced by
It seems like seeHttpHeaderOnce() 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...
47
        $this->seeHttpHeaderOnce('X-Pagination-Per-Page');
0 ignored issues
show
Bug introduced by
It seems like seeHttpHeaderOnce() 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...
48
    }
49
50
    /**
51
     * Checks over the HTTP content type header value.
52
     */
53
    public function seeContentTypeHttpHeader(
54
        $contentType = Tester::HAL_JSON_CONTENT_TYPE
55
    ) {
56
        $this->seeHttpHeader('Content-Type', $contentType);
0 ignored issues
show
Bug introduced by
It seems like seeHttpHeader() 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...
57
    }
58
}
59