Skip to content

Commit 33f444f

Browse files
committed
Some fixes for Scrutinizer
1 parent 5911fd8 commit 33f444f

File tree

8 files changed

+56
-19
lines changed

8 files changed

+56
-19
lines changed

scrutinizer.yml .scrutinizer.yml

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ tools:
2020
external_code_coverage:
2121
timeout: 600
2222
runs: 3
23+
php_analyzer: true
2324
php_code_coverage: false
2425
php_code_sniffer:
2526
config:

.travis.yml

+5
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,13 @@ php:
44
- 5.4
55
- 5.5
66
- 5.6
7+
- 7.0
78
- hhvm
89

10+
matrix:
11+
allow_failures:
12+
- php: 7.0
13+
914
before_script:
1015
- travis_retry composer self-update
1116
- travis_retry composer install --no-interaction --prefer-source

CONTRIBUTING.md

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
Contributions are **welcome** and will be fully **credited**.
44
Send Pull Requests or open issues please.
55

6+
Active TODOs can be seen [here](TODO.md).
7+
68
## Pull Requests
79

810
- **[PSR-2 Coding Standard](https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md)** - The easiest way to apply the conventions is to install [PHP Code Sniffer](http://pear.php.net/package/PHP_CodeSniffer).

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
![Travis Build Badge](https://travis-ci.org/Swader/diffbot-php-client.svg?branch=master)
1+
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/Swader/diffbot-php-client/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/Swader/diffbot-php-client/?branch=master)
2+
[![Code Coverage](https://scrutinizer-ci.com/g/Swader/diffbot-php-client/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/Swader/diffbot-php-client/?branch=master)
3+
[![Build Status](https://scrutinizer-ci.com/g/Swader/diffbot-php-client/badges/build.png?b=master)](https://scrutinizer-ci.com/g/Swader/diffbot-php-client/build-status/master)
24

35
# Diffbot PHP API Wrapper
46

TODO.md

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Active TODOs
2+
3+
Active todos, ordered by priority
4+
5+
## High
6+
7+
- implement Discussion API
8+
- implement Crawlbot
9+
- implement Search API
10+
11+
## Medium
12+
13+
- add streaming to Crawlbot - make it stream the result (it constantly grows)
14+
- implement Video API (currently beta)
15+
- improve Custom API
16+
- improve Wildcard Entity - apply to Custom API
17+
18+
## Low
19+
20+
- get more mock responses and test against them

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"keywords": [
55
"diffbot", "api", "wrapper", "client"
66
],
7-
"homepage": "https://github.com/swader/diffbot_client",
7+
"homepage": "https://github.com/swader/diffbot-php-client",
88
"license": "MIT",
99
"authors": [
1010
{

src/Abstracts/Api.php

+24-16
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,20 @@ abstract class Api implements \Swader\Diffbot\Interfaces\Api
3131

3232
public function __construct($url)
3333
{
34-
if (!is_string($url)) {
35-
throw new \InvalidArgumentException('URL param must be a string.');
36-
}
37-
$url = trim($url);
34+
$url = trim((string)$url);
3835
if (strlen($url) < 4) {
39-
throw new \InvalidArgumentException('URL must be at least four characters in length');
40-
}
41-
if ($parts = parse_url($url)) {
42-
if (!isset($parts["scheme"])) {
43-
$url = "http://$url";
44-
}
36+
throw new \InvalidArgumentException(
37+
'URL must be a string of at least four characters in length'
38+
);
4539
}
40+
41+
$url = (isset(parse_url($url)['scheme'])) ? $url : "http://$url";
42+
4643
$filtered_url = filter_var($url, FILTER_VALIDATE_URL);
47-
if (false === $filtered_url) {
48-
throw new \InvalidArgumentException('You provided an invalid URL: ' . $url);
44+
if (!$filtered_url) {
45+
throw new \InvalidArgumentException(
46+
'You provided an invalid URL: ' . $url
47+
);
4948
}
5049

5150
$this->url = $filtered_url;
@@ -54,7 +53,8 @@ public function __construct($url)
5453
/**
5554
* Setting the timeout will define how long Diffbot will keep trying
5655
* to fetch the API results. A timeout can happen for various reasons, from
57-
* Diffbot's failure, to the site being crawled being exceptionally slow, and more.
56+
* Diffbot's failure, to the site being crawled being exceptionally slow,
57+
* and more.
5858
*
5959
* @param int|null $timeout Defaults to 30000 even if not set
6060
*
@@ -69,17 +69,24 @@ public function setTimeout($timeout = null)
6969
throw new \InvalidArgumentException('Parameter is not an integer');
7070
}
7171
if ($timeout < 0) {
72-
throw new \InvalidArgumentException('Parameter is negative. Only positive timeouts accepted.');
72+
throw new \InvalidArgumentException(
73+
'Parameter is negative. Only positive timeouts accepted.'
74+
);
7375
}
7476

7577
$this->timeout = $timeout;
78+
7679
return $this;
7780
}
7881

7982
public function call()
8083
{
8184
$response = $this->diffbot->getHttpClient()->get($this->buildUrl());
82-
return $this->diffbot->getEntityFactory()->createAppropriateIterator($response);
85+
86+
return $this
87+
->diffbot
88+
->getEntityFactory()
89+
->createAppropriateIterator($response);
8390
}
8491

8592
public function buildUrl()
@@ -106,7 +113,7 @@ public function buildUrl()
106113

107114
// Add Other Options
108115
foreach ($this->otherOptions as $option => $value) {
109-
$url .= '&'.$option . '=' . $value;
116+
$url .= '&' . $option . '=' . $value;
110117
}
111118

112119
return $url;
@@ -121,6 +128,7 @@ public function buildUrl()
121128
public function registerDiffbot(Diffbot $d)
122129
{
123130
$this->diffbot = $d;
131+
124132
return $this;
125133
}
126134

tests/Abstracts/ApiTest.php

-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ public function invalidUrls()
9696
return [
9797
'bool' => [false],
9898
'null' => [null],
99-
'number' => [12345],
10099
'abc' => ['abc'],
101100
'misc_string' => ['35tugz---sdf----?//*****/*//*']
102101
];

0 commit comments

Comments
 (0)