CreateTrait   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A _dir() 0 7 2
A create() 0 7 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
    /**
14
     * The `POST` directory. Defaults to including the container.
15
     *
16
     * @return string
17
     */
18
    protected function _dir(): string
19
    {
20
        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

20
        if ($container = $this->/** @scrutinizer ignore-call */ _container()) {
Loading history...
21
            assert($container->hasId());
22
            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...
23
        }
24
        return static::DIR;
25
    }
26
27
    /**
28
     * @return $this
29
     */
30
    public function create()
31
    {
32
        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

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

33
        $remote = $this->api->post($this->_dir(), [static::TYPE => $this->/** @scrutinizer ignore-call */ toArray()]);
Loading history...
34
        $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

34
        $this->/** @scrutinizer ignore-call */ 
35
               _setData($remote[static::TYPE]);
Loading history...
35
        $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

35
        $this->/** @scrutinizer ignore-call */ 
36
               _onSave();
Loading history...
36
        return $this;
37
    }
38
}