Skip to content

Commit

Permalink
Update phpstan
Browse files Browse the repository at this point in the history
  • Loading branch information
richardm-stripe committed Dec 1, 2021
1 parent a6be5eb commit 9667937
Show file tree
Hide file tree
Showing 13 changed files with 25 additions and 26 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,9 @@ jobs:
fail-fast: false
matrix:
php-version:
- "7.1"
- "7.4"
- "8.1"

steps:
- uses: actions/checkout@master
Expand Down Expand Up @@ -102,6 +104,12 @@ jobs:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('composer.json') }}

# We run PHPStan in a separate job, and the version of PHPStan we use is not compatible
# with all the versions we support and run unit tests for. We need to temporarily remove it
# from composer.json here, else composer install will fail due the version incompatibility.
- name: Trim dependency
run: composer remove --dev phpstan/phpstan

- name: Validate composer.json and composer.lock
run: composer validate

Expand Down
6 changes: 1 addition & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ export PHPSTAN_VERSION := 0.12.59
vendor: composer.json
composer install

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

vendor/bin/phpdoc: vendor
curl -sfL https://github.com/phpDocumentor/phpDocumentor/releases/download/$(PHPDOCUMENTOR_VERSION)/phpDocumentor.phar -o vendor/bin/phpdoc
chmod +x vendor/bin/phpdoc
Expand All @@ -27,7 +23,7 @@ fmtcheck: vendor
phpdoc: vendor/bin/phpdoc
vendor/bin/phpdoc

phpstan: vendor/bin/phpstan
phpstan: vendor
php -d memory_limit=512M vendor/bin/phpstan analyse lib tests
.PHONY: phpstan

Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
"phpunit/phpunit": "^5.7 || ^9.0",
"php-coveralls/php-coveralls": "^2.1",
"squizlabs/php_codesniffer": "^3.3",
"friendsofphp/php-cs-fixer": "3.2.1 || 2.17.1"
"friendsofphp/php-cs-fixer": "3.2.1 || 2.17.1",
"phpstan/phpstan": "^1.2"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 0 additions & 2 deletions lib/ApiOperations/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ protected function _request($method, $url, $params = [], $options = null)
* @param null|array|string $options
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return array tuple containing (the JSON response, $options)
*/
protected function _requestStream($method, $url, $readBodyChunk, $params = [], $options = null)
{
Expand Down
2 changes: 0 additions & 2 deletions lib/ApiRequestor.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,6 @@ public function request($method, $url, $params = null, $headers = null)
* @param null|array $headers
*
* @throws Exception\ApiErrorException
*
* @return array tuple containing (ApiReponse, API key)
*/
public function requestStream($method, $url, $readBodyChunkCallable, $params = null, $headers = null)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/ApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ public static function classUrl()
{
// Replace dots with slashes for namespaced resources, e.g. if the object's name is
// "foo.bar", then its URL will be "/v1/foo/bars".

/** @phpstan-ignore-next-line */
$base = \str_replace('.', '/', static::OBJECT_NAME);

return "/v1/{$base}s";
Expand Down
2 changes: 2 additions & 0 deletions lib/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ public function deleteDiscount($params = null, $opts = null)
$url = $this->instanceUrl() . '/discount';
list($response, $opts) = $this->_request('delete', $url, $params, $opts);
$this->refreshFrom(['discount' => null], $opts, true);

return $this;
}

/**
Expand Down
2 changes: 0 additions & 2 deletions lib/Quote.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,6 @@ class Quote extends ApiResource
* @param null|array|string $opts
*
* @throws \Stripe\Exception\ApiErrorException if the request fails
*
* @return \Stripe\File the created file
*/
public function pdf($readBodyChunkCallable, $params = null, $opts = null)
{
Expand Down
2 changes: 2 additions & 0 deletions lib/SingletonApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ public static function classUrl()
{
// Replace dots with slashes for namespaced resources, e.g. if the object's name is
// "foo.bar", then its URL will be "/v1/foo/bar".

/** @phpstan-ignore-next-line */
$base = \str_replace('.', '/', static::OBJECT_NAME);

return "/v1/{$base}";
Expand Down
2 changes: 2 additions & 0 deletions lib/Subscription.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,5 +114,7 @@ public function deleteDiscount($params = null, $opts = null)
$url = $this->instanceUrl() . '/discount';
list($response, $opts) = $this->_request('delete', $url, $params, $opts);
$this->refreshFrom(['discount' => null], $opts, true);

return $this;
}
}
12 changes: 0 additions & 12 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,12 +0,0 @@
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

6 changes: 6 additions & 0 deletions tests/TestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ class TestCase extends \PHPUnit\Framework\TestCase
public static function compatAssertIsArray($obj)
{
if (method_exists(static::class, 'assertIsArray')) {
// @phpstan-ignore-next-line
static::assertIsArray($obj);
} else {
// @phpstan-ignore-next-line
Expand All @@ -26,6 +27,7 @@ public static function compatAssertIsArray($obj)
public function compatExpectExceptionMessageMatches($msg)
{
if (method_exists($this, 'expectExceptionMessageMatches')) {
// @phpstan-ignore-next-line
$this->expectExceptionMessageMatches($msg);
} else {
// @phpstan-ignore-next-line
Expand All @@ -36,15 +38,18 @@ public function compatExpectExceptionMessageMatches($msg)
public static function compatAssertStringContainsString($a, $b)
{
if (method_exists(static::class, 'assertStringContainsString')) {
// @phpstan-ignore-next-line
static::assertStringContainsString($a, $b);
} else {
// @phpstan-ignore-next-line
static::assertContains($a, $b);
}
}

public function compatAssertIsString($x)
{
if (method_exists($this, 'assertIsString')) {
// @phpstan-ignore-next-line
static::assertIsString($x);
} else {
// @phpstan-ignore-next-line
Expand All @@ -55,6 +60,7 @@ public function compatAssertIsString($x)
public static function compatWarningClass()
{
if (class_exists('\PHPUnit\Framework\Error\Warning')) {
// @phpstan-ignore-next-line
return \PHPUnit\Framework\Error\Warning::class;
}

Expand Down
2 changes: 0 additions & 2 deletions tests/TestHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,8 +153,6 @@ function ($method, $absUrl, $readBodyChunkCallable, $headers, $params, $hasFile)
* @param array $response
* @param int $rcode
* @param null|string $base
*
* @return array
*/
protected function stubRequest(
$method,
Expand Down

0 comments on commit 9667937

Please sign in to comment.