XisbnClient   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
c 0
b 0
f 0
lcom 1
cbo 1
dl 0
loc 35
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A makeQuery() 0 8 1
A checkIsbns() 0 13 2
1
<?php
2
3
namespace Colligator;
4
5
class XisbnClient
6
{
7
    /**
8
     * @var string
9
     */
10
    public $baseUrl;
11
12
    public function __construct()
13
    {
14
        $this->baseUrl = 'http://xisbn.worldcat.org/webservices/xid/isbn';
15
    }
16
17
    public function makeQuery($method = 'getEditions', $format = 'json', $fields = 'form,year,lang,ed,lccn,oclcnum,originalLang,publisher,url')
18
    {
19
        return http_build_query([
20
            'method' => $method,
21
            'format' => $format,
22
            'fl'     => $fields,
23
        ]);
24
    }
25
26
    public function checkIsbns($isbns)
27
    {
28
        $response = [];
29
        foreach ($isbns as $isbn) {
30
            $isbn = preg_replace('/[^0-9]/', '', $isbn);
31
            $url = sprintf('%s/%s?%s', $this->baseUrl, $isbn, $this->makeQuery());
32
33
            // TODO: Use Guzzle, so we can mock and test
34
            $response[$isbn] = json_decode(file_get_contents($url), true);
35
        }
36
37
        return new XisbnResponse($response);
38
    }
39
}
40