Passed
Push — master ( 199ece...6bc7da )
by y
02:13
created

CreateTrait   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 24
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _dir() 0 6 2
A create() 0 6 1
1
<?php
2
3
namespace Helix\Shopify\Base\AbstractEntity;
4
5
use Helix\Shopify\Base\AbstractEntity;
6
7
/**
8
 * @mixin AbstractEntity
9
 */
10
trait CreateTrait {
11
12
    /**
13
     * The `POST` directory. Defaults to including the container.
14
     *
15
     * @return string
16
     */
17
    protected function _dir (): string {
18
        if ($container = $this->_container()) {
0 ignored issues
show
Bug introduced by
It seems like _container() 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
        if ($container = $this->/** @scrutinizer ignore-call */ _container()) {
Loading history...
19
            assert($container->hasId());
20
            return "{$container}/" . static::DIR;
0 ignored issues
show
Bug introduced by
The constant Helix\Shopify\Base\AbstractEntity\CreateTrait::DIR was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
21
        }
22
        return static::DIR;
23
    }
24
25
    /**
26
     * @return $this
27
     */
28
    public function create () {
29
        assert(!$this->hasId());
0 ignored issues
show
Bug introduced by
It seems like hasId() 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

29
        assert(!$this->/** @scrutinizer ignore-call */ hasId());
Loading history...
30
        $remote = $this->api->post($this->_dir(), [static::TYPE => $this->toArray()]);
0 ignored issues
show
Bug introduced by
It seems like toArray() 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

30
        $remote = $this->api->post($this->_dir(), [static::TYPE => $this->/** @scrutinizer ignore-call */ toArray()]);
Loading history...
Bug introduced by
The constant Helix\Shopify\Base\Abstr...ntity\CreateTrait::TYPE was not found. Maybe you did not declare it correctly or list all dependencies?
Loading history...
31
        $this->_setData($remote[static::TYPE]);
0 ignored issues
show
Bug introduced by
It seems like _setData() 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

31
        $this->/** @scrutinizer ignore-call */ 
32
               _setData($remote[static::TYPE]);
Loading history...
32
        $this->_onSave();
0 ignored issues
show
Bug introduced by
It seems like _onSave() 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

32
        $this->/** @scrutinizer ignore-call */ 
33
               _onSave();
Loading history...
33
        return $this;
34
    }
35
}