Test Failed
Push — master ( 7c4720...fd955c )
by Lyal
04:00 queued 14s
created

Creatable   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 45
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getCreatePath() 0 3 1
A setCreatePath() 0 3 1
A create() 0 11 2
1
<?php
2
namespace Lyal\Checkr\Traits;
3
4
use Lyal\Checkr\Exceptions\ResourceNotCreated;
5
6
trait Creatable
7
{
8
    protected $createPath;
9
10
    /**
11
     * Post a resource and update this parameters with the response from the API
12
     * @return $this
13
     * @throws ResourceNotCreated
14
     */
15
16
    public function create()
17
    {
18
        $path = $this->getCreatePath() ?? $this->getResourceName();
0 ignored issues
show
Bug introduced by
It seems like getResourceName() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

18
        $path = $this->getCreatePath() ?? $this->/** @scrutinizer ignore-call */ getResourceName();
Loading history...
19
20
        $response = $this->postRequest($path);
0 ignored issues
show
Bug introduced by
It seems like postRequest() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

20
        /** @scrutinizer ignore-call */ 
21
        $response = $this->postRequest($path);
Loading history...
21
        $this->setAttributes([]);
0 ignored issues
show
Bug introduced by
It seems like setAttributes() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

21
        $this->/** @scrutinizer ignore-call */ 
22
               setAttributes([]);
Loading history...
22
        $this->setValues($response);
0 ignored issues
show
Bug introduced by
It seems like setValues() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

22
        $this->/** @scrutinizer ignore-call */ 
23
               setValues($response);
Loading history...
23
        if ($this->getClient()->getLastResponse()->getStatusCode() !== 201) {
0 ignored issues
show
Bug introduced by
It seems like getClient() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

23
        if ($this->/** @scrutinizer ignore-call */ getClient()->getLastResponse()->getStatusCode() !== 201) {
Loading history...
24
            throw new ResourceNotCreated($this->getClient()->getLastResponse()->getBody());
25
        }
26
        return $this;
27
    }
28
29
30
    /**
31
     * Get the create path of the current object
32
     *
33
     * @return string
34
     */
35
36
    public function getCreatePath()
37
    {
38
        return $this->createPath;
39
    }
40
41
    /**
42
     * Set the save path of the current object
43
     *
44
     * @param $path
45
     * @return mixed
46
     */
47
48
    public function setCreatePath($path)
49
    {
50
        return $this->createPath = $path;
51
    }
52
53
}