Passed
Push — master ( b1ea1f...f2eb6e )
by Radosław
02:44
created

Helper   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 137
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 12
lcom 1
cbo 3
dl 0
loc 137
ccs 0
cts 46
cp 0
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getFieldsByCategory() 0 15 1
A newAuction() 0 14 3
A finishAuction() 0 4 1
A finishAuctions() 0 12 1
A changeQuantity() 0 7 1
A getSiteJournalDeals() 0 9 2
A getAuctionByItemId() 0 11 2
1
<?php
2
3
namespace Radowoj\Yaah;
4
5
use Radowoj\Yaah\Constants\SellFormOpts;
6
7
class Helper
8
{
9
    protected $client = null;
10
11
    public function __construct(Client $client)
12
    {
13
        $this->client = $client;
14
    }
15
16
    /**
17
     * Get simplified fields list for given category
18
     * @param  integer $idCategory id of category in question
19
     * @return array of fields metadata
20
     */
21
    public function getFieldsByCategory($idCategory)
22
    {
23
        $data = $this->client->getSellFormFieldsForCategory(['categoryId' => $idCategory]);
0 ignored issues
show
Documentation Bug introduced by
The method getSellFormFieldsForCategory does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
24
        $items = $data->sellFormFieldsForCategory->sellFormFieldsList->item;
25
26
        return array_map(function ($item) {
27
            return [
28
                'fid' => $item->sellFormId,
29
                'title' => $item->sellFormTitle,
30
                'required' => ($item->sellFormOpt == SellFormOpts::SELL_FORM_OPT_REQUIRED),
31
                'options' => $item->sellFormOptsValues,
32
                'optionsDesc' => $item->sellFormDesc,
33
            ];
34
        }, $items);
35
    }
36
37
    /**
38
     * Create new auction
39
     *
40
     * @throws Exception on failure
41
     *
42
     * @param  Auction $auction Auction to create
43
     * @param integer $localId - local item id, required by WebAPI
44
     * @return integer id of created auction
45
     */
46
    public function newAuction(AuctionInterface $auction, $localId)
47
    {
48
        $auctionArray = $auction->toApiRepresentation();
49
        $auctionArray['localId'] = $localId;
50
51
        $resultNewAuction = $this->client->newAuctionExt($auctionArray);
0 ignored issues
show
Documentation Bug introduced by
The method newAuctionExt does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
Unused Code introduced by
$resultNewAuction is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
52
        $resultVerify = $this->client->verifyItem(['localId' => $localId]);
0 ignored issues
show
Documentation Bug introduced by
The method verifyItem does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
53
54
        if (!is_object($resultVerify) || !isset($resultVerify->itemId)) {
55
            throw new Exception("Auction has not been created: " . print_r($resultVerify, 1));
56
        }
57
58
        return $resultVerify->itemId;
59
    }
60
61
62
    /**
63
     * Finish a single auction
64
     * @param  integer $auctionId itemId of auction to finish
65
     * @param  integer $cancelAllBids whether to cancel all bids
66
     * @param  string  $finishCancelReason reason
67
     * @return array
68
     */
69
    public function finishAuction($auctionId, $cancelAllBids = 0, $finishCancelReason = '')
70
    {
71
        return $this->finishAuctions((array)($auctionId), $cancelAllBids, $finishCancelReason);
72
    }
73
74
75
    /**
76
     * Finish a single auction
77
     * @param  array $auctionIds itemIds of auctions to finish
78
     * @param  integer $cancelAllBids whether to cancel all bids
79
     * @param  string  $finishCancelReason reason
80
     * @return array
81
     */
82
    public function finishAuctions(array $auctionIds, $cancelAllBids = 0, $finishCancelReason = '')
83
    {
84
        $finishItemsList = array_map(function ($auctionId) use ($cancelAllBids, $finishCancelReason) {
85
            return [
86
                'finishItemId' => $auctionId,
87
                'finishCancelAllBids' => $cancelAllBids,
88
                'finishCancelReason' => $finishCancelReason,
89
            ];
90
        }, $auctionIds);
91
92
        return $this->client->finishItems(['finishItemsList' => $finishItemsList]);
0 ignored issues
show
Documentation Bug introduced by
The method finishItems does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
93
    }
94
95
    /**
96
     * Change quantity of items available in auction
97
     * @param  integer $auctionId   itemId of auction to change quantity
98
     * @param  integer $newQuantity new quantity to set
99
     * @return array
100
     */
101
    public function changeQuantity($auctionId, $newQuantity)
102
    {
103
        return $this->client->changeQuantityItem([
0 ignored issues
show
Documentation Bug introduced by
The method changeQuantityItem does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
104
            'itemId' => $auctionId,
105
            'newItemQuantity' => $newQuantity
106
        ]);
107
    }
108
109
110
    /**
111
     * Return site journal deals
112
     * @param  integer $journalStart start point (dealEventId)
113
     * @return array
114
     */
115
    public function getSiteJournalDeals($journalStart)
116
    {
117
        $response = $this->client->getSiteJournalDeals(['journalStart' => $journalStart]);
0 ignored issues
show
Documentation Bug introduced by
The method getSiteJournalDeals does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
118
        if (isset($response->siteJournalDeals->item)) {
119
            return $response->siteJournalDeals->item;
120
        }
121
122
        throw new Exception("Unable to get site journal deals: " . print_r($response, 1));
123
    }
124
125
126
    /**
127
     * @param  integer $itemId id of auction to get
128
     * @return Auction | null
129
     */
130
    public function getAuctionByItemId($itemId)
131
    {
132
        $response =  $this->client->getItemFields(['itemId' => $itemId]);
0 ignored issues
show
Documentation Bug introduced by
The method getItemFields does not exist on object<Radowoj\Yaah\Client>? Since you implemented __call, maybe consider adding a @method annotation.

If you implement __call and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.

This is often the case, when __call is implemented by a parent class and only the child class knows which methods exist:

class ParentClass {
    private $data = array();

    public function __call($method, array $args) {
        if (0 === strpos($method, 'get')) {
            return $this->data[strtolower(substr($method, 3))];
        }

        throw new \LogicException(sprintf('Unsupported method: %s', $method));
    }
}

/**
 * If this class knows which fields exist, you can specify the methods here:
 *
 * @method string getName()
 */
class SomeClass extends ParentClass { }
Loading history...
133
        if (isset($response->itemFields->item)) {
134
            $auction = new Auction();
135
            $auction->fromApiRepresentation($response->itemFields->item);
136
            return $auction;
137
        }
138
139
        return null;
140
    }
141
142
143
}
144