Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use PHPStan in Travis CI #787

Merged
merged 1 commit into from
Oct 30, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,9 @@ charset = utf-8

[*.{json,yml}]
indent_size = 2

[*.neon]
indent_style = tab

[Makefile]
indent_style = tab
3 changes: 2 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ cache:
before_install:
# Install various build dependencies. We use `travis_retry` because Composer
# will occasionally fail intermittently.
- travis_retry composer install
- travis_retry make vendor

# Unpack and start stripe-mock so that the test suite can talk to it
- |
Expand All @@ -68,5 +68,6 @@ before_install:
script:
- ./build.php ${AUTOLOAD}
- ./vendor/bin/php-cs-fixer fix -v --dry-run --using-cache=no .
- if [[ `php -r "echo \version_compare(PHP_VERSION, '7.1', '>=');"` && $AUTOLOAD == 1 ]]; then make phpstan; fi

after_script: ./vendor/bin/coveralls -v
22 changes: 22 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
export PHPSTAN_VERSION := 0.11.19

vendor: composer.json
composer install
curl -sfL https://github.com/phpstan/phpstan/releases/download/$(PHPSTAN_VERSION)/phpstan.phar -o vendor/bin/phpstan
chmod +x vendor/bin/phpstan

test: vendor
vendor/bin/phpunit
.PHONY: test

fmt: vendor
vendor/bin/php-cs-fixer fix -v --using-cache=no .
.PHONY: fmt

phpstan: vendor
vendor/bin/phpstan analyse -c phpstan.neon lib tests
.PHONY: phpstan

phpstan-baseline: vendor
vendor/bin/phpstan analyse -c phpstan.neon --error-format baselineNeon lib tests > phpstan-baseline.neon
.PHONY: phpstan-baseline
2 changes: 1 addition & 1 deletion lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ public function handleErrorResponse($rbody, $rcode, $rheaders, $resp)
if (!is_array($resp) || !isset($resp['error'])) {
$msg = "Invalid response object from API: $rbody "
. "(HTTP response code was $rcode)";
throw new Exception\UnexpectedValueException($msg, $rcode, $rbody, $resp, $rheaders);
throw new Exception\UnexpectedValueException($msg);
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
}

$errorData = $resp['error'];
Expand Down
2 changes: 1 addition & 1 deletion lib/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* @property StripeObject $metadata
* @property string $name
* @property string $phone
* @property string[] preferred_locales
* @property string[] $preferred_locales
* @property mixed $shipping
* @property Collection $sources
* @property Collection $subscriptions
Expand Down
7 changes: 5 additions & 2 deletions lib/HttpClient/CurlClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ public static function instance()

protected $defaultOptions;

/** @var \Stripe\Util\RandomGenerator */
protected $randomGenerator;

ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
protected $userAgentInfo;

protected $enablePersistentConnections = true;
Expand Down Expand Up @@ -380,7 +383,7 @@ private function handleCurlError($url, $errno, $message, $numRetries)
*
* @param int $errno
* @param int $rcode
* @param array|CaseInsensitiveArray $rheaders
* @param array|\Stripe\Util\CaseInsensitiveArray $rheaders
* @param int $numRetries
*
* @return bool
Expand Down Expand Up @@ -435,7 +438,7 @@ private function shouldRetry($errno, $rcode, $rheaders, $numRetries)
* Provides the number of seconds to wait before retrying a request.
*
* @param int $numRetries
* @param array|CaseInsensitiveArray $rheaders
* @param array|\Stripe\Util\CaseInsensitiveArray $rheaders
*
* @return int
*/
Expand Down
2 changes: 1 addition & 1 deletion lib/StripeObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ public function serializeParamsValue($value, $original, $unsaved, $force, $key =
// user intended it to.
if ($value === null) {
return "";
} elseif (($value instanceof APIResource) && (!$value->saveWithParent)) {
} elseif (($value instanceof ApiResource) && (!$value->saveWithParent)) {
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
if (!$unsaved) {
return null;
} elseif (isset($value->id)) {
Expand Down
15 changes: 15 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@


parameters:
ignoreErrors:
-
message: "#^Access to undefined constant Stripe\\\\ApiResource\\:\\:OBJECT_NAME\\.$#"
count: 1
path: lib/ApiResource.php

-
message: "#^Access to undefined constant Stripe\\\\SingletonApiResource\\:\\:OBJECT_NAME\\.$#"
count: 1
path: lib/SingletonApiResource.php
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved


8 changes: 8 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
includes:
- phpstan-baseline.neon

parameters:
level: 1
bootstrap: tests/bootstrap.php
autoload_directories:
- tests
3 changes: 3 additions & 0 deletions tests/Stripe/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class CollectionTest extends TestCase
{
/** @var \Stripe\Collection */
private $fixture;

/**
* @before
*/
Expand Down
23 changes: 22 additions & 1 deletion tests/Stripe/HttpClient/CurlClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,27 @@

class CurlClientTest extends TestCase
{
/** @var \ReflectionProperty */
private $initialNetworkRetryDelayProperty;

/** @var \ReflectionProperty */
private $maxNetworkRetryDelayProperty;

/** @var double */
private $origInitialNetworkRetryDelay;

/** @var int */
private $origMaxNetworkRetries;

/** @var double */
private $origMaxNetworkRetryDelay;

/** @var \ReflectionMethod */
private $sleepTimeMethod;

/** @var \ReflectionMethod */
private $shouldRetryMethod;

/**
* @before
*/
Expand Down Expand Up @@ -60,7 +81,7 @@ private function setInitialNetworkRetryDelay($initialNetworkRetryDelay)

private function createFakeRandomGenerator($returnValue = 1.0)
{
$fakeRandomGenerator = $this->createMock('Stripe\Util\RandomGenerator', ['randFloat']);
$fakeRandomGenerator = $this->createMock('Stripe\Util\RandomGenerator');
ob-stripe marked this conversation as resolved.
Show resolved Hide resolved
$fakeRandomGenerator->method('randFloat')->willReturn($returnValue);
return $fakeRandomGenerator;
}
Expand Down
6 changes: 6 additions & 0 deletions tests/Stripe/StripeObjectTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@

class StripeObjectTest extends TestCase
{
/** @var \ReflectionMethod */
private $deepCopyReflector;

/** @var \ReflectionMethod */
private $optsReflector;

/**
* @before
*/
Expand Down
3 changes: 3 additions & 0 deletions tests/Stripe/StripeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@

class StripeTest extends TestCase
{
/** @var array */
protected $orig;

/**
* @before
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ protected function stubRequest(
* Defaults to false.
* @param string|null $base base URL (e.g. 'https://api.stripe.com')
*
* @return PHPUnit_Framework_MockObject_Builder_InvocationMocker
* @return \PHPUnit_Framework_MockObject_Builder_InvocationMocker
*/
private function prepareRequestMock(
$method,
Expand Down