AbeBooksPriceClient   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 50
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 50
ccs 36
cts 36
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getPricesForIsbns() 0 9 2
C addPricesToCollection() 0 28 8
1
<?php namespace Packback\Prices\Clients;
2
3
use Packback\Prices\PriceClient;
4
5
class AbeBooksPriceClient extends PriceClient
6
{
7
    const RETAILER = 'abebooks';
8
9 10
    public function __construct($config = [])
10
    {
11 10
        parent::__construct();
12 10
        $this->baseUrl = 'http://search2.abebooks.com/search';
13 10
        $this->query['clientkey'] = $config['access_key'];
14 10
    }
15
16 2
    public function getPricesForIsbns($isbns = [])
17
    {
18 2
        foreach ($isbns as $isbn) {
19 2
            $response = $this->addParam('isbn', $isbn)->send();
20 2
            $this->addPricesToCollection($response);
21 2
        }
22
23 2
        return $this->collection;
24
    }
25
26 10
    public function addPricesToCollection($response)
27
    {
28
        // Check response, populate price object, send collection back
29 10
        if (isset($response['Book'])) {
30 8
            foreach ($response['Book'] as $offer) {
31 8
                $offer = (object) $offer;
32 8
                $price = $this->createNewPrice();
33 8
                if (isset($offer->listingPrice)) {
34 8
                    if (isset($offer->listingCondition) && strtolower($offer->listingCondition) == 'new book') {
35 2
                        $price->condition = parent::CONDITION_NEW;
36 8
                    } elseif (isset($offer->itemCondition)) {
37 4
                        $price->condition = $this->getConditionFromString($offer->itemCondition);
38 4
                    }
39 8
                    if (empty($price->condition)) {
40 2
                        $price->condition = parent::CONDITION_GOOD;
41 2
                    }
42 8
                    $price->isbn13 = $offer->isbn13;
43 8
                    $price->price = $offer->listingPrice;
44 8
                    $price->shipping_price = $offer->firstBookShipCost;
45 8
                    $price->url = 'http://affiliates.abebooks.com/c/74871/77797/2029?u='.urlencode($offer->listingUrl);
46 8
                    $price->retailer = self::RETAILER;
47 8
                    $price->term = parent::TERM_PERPETUAL;
48 8
                }
49 8
                $this->addPriceToCollection($price);
50 8
            }
51 8
        }
52 10
        return $this;
53
    }
54
}
55