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

Add phpstan for static analysis #194

Merged
merged 2 commits into from Feb 9, 2021
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
12 changes: 9 additions & 3 deletions .github/workflows/build.yml
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
matrix:
php: [ '7.3', '7.4' ]

steps:
- uses: actions/checkout@v2
name: Checkout repository
Expand All @@ -28,6 +28,12 @@ jobs:
- name: Static Code Analysis
run: composer lint

- uses: docker://oskarstark/phpstan-ga
env:
REQUIRE_DEV: true
with:
args: analyse src/ --level=5

test:
runs-on: ${{ matrix.operating-system }}
needs:
Expand All @@ -50,10 +56,10 @@ jobs:
with:
php-version: ${{ matrix.php }}

- name: Copy the inis
- name: Copy the inis
if: runner.os == 'Windows'
run: Copy-Item -Path .\tests\PhpPact\php.ini -Destination C:\tools\php\ -Force

- name: Composer install
uses: ramsey/composer-install@v1
with:
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Expand Up @@ -32,11 +32,11 @@
"amphp/serialization": "^1.0",
"amphp/socket": "^1.1.3",
"amphp/sync": "^1.4.0",
"guzzlehttp/guzzle": "^7.2.0"
"guzzlehttp/guzzle": "^7.2.0",
"phpunit/phpunit": ">=8.2.3"
},
"require-dev": {
"roave/security-advisories": "dev-master",
"phpunit/phpunit": "^9.4.3",
"mockery/mockery": "^1.4.2",
"slim/slim": "^4.6",
"slim/psr7": "^1.2.0",
Expand Down
6 changes: 4 additions & 2 deletions src/PhpPact/Consumer/Hook/ContractDownloader.php
Expand Up @@ -5,6 +5,8 @@
use Exception;
use PhpPact\Http\ClientInterface;
use PhpPact\Http\GuzzleClient;
use PhpPact\Standalone\Exception\MissingEnvVariableException;
use PhpPact\Standalone\MockService\MockServerConfig;
use PhpPact\Standalone\MockService\MockServerEnvConfig;
use PhpPact\Standalone\MockService\Service\MockServerHttpService;
use PHPUnit\Framework\AssertionFailedError;
Expand All @@ -13,10 +15,10 @@

class ContractDownloader implements AfterLastTestHook
{
/** @var MockServerConfigInterface */
/** @var MockServerConfig */
private $mockServerConfig;

/** @var ClientInterface */
/** @var null|ClientInterface */
private $client;

/**
Expand Down
5 changes: 2 additions & 3 deletions src/PhpPact/Consumer/Listener/PactTestListener.php
Expand Up @@ -7,7 +7,6 @@
use PhpPact\Http\GuzzleClient;
use PhpPact\Standalone\Exception\MissingEnvVariableException;
use PhpPact\Standalone\MockService\MockServer;
use PhpPact\Standalone\MockService\MockServerConfigInterface;
use PhpPact\Standalone\MockService\MockServerEnvConfig;
use PhpPact\Standalone\MockService\Service\MockServerHttpService;
use PHPUnit\Framework\AssertionFailedError;
Expand All @@ -30,11 +29,11 @@ class PactTestListener implements TestListener
/**
* Name of the test suite configured in your phpunit config.
*
* @var string
* @var string[]
*/
private $testSuiteNames;

/** @var MockServerConfigInterface */
/** @var MockServerEnvConfig */
private $mockServerConfig;

/** @var bool */
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPact/Consumer/Matcher/Matcher.php
Expand Up @@ -21,7 +21,7 @@ class Matcher
/**
* Alias for the `like()` function.
*
* @param $value
* @param mixed $value
*
* @throws \Exception
*
Expand Down Expand Up @@ -107,7 +107,7 @@ public function term($value, string $pattern): array
/**
* Alias for the term matcher.
*
* @param $value
* @param mixed $value
* @param string $pattern
*
* @throws \Exception
Expand Down
18 changes: 10 additions & 8 deletions src/PhpPact/Consumer/MessageBuilder.php
Expand Up @@ -25,7 +25,7 @@ class MessageBuilder implements BuilderInterface
private $message;

/**
* constructor.
* @param PactConfigInterface $config
*/
public function __construct(PactConfigInterface $config)
{
Expand All @@ -37,8 +37,8 @@ public function __construct(PactConfigInterface $config)
/**
* Retrieve the verification call back
*
* @param callable $callback
* @param string $description of the call back in case of multiple
* @param callable $callback
* @param false|string $description of the callback in case of multiple
*
* @return MessageBuilder
*/
Expand Down Expand Up @@ -96,7 +96,7 @@ public function withMetadata($metadata): self
*
* @param mixed $contents required to be in the message
*
* @return bool returns true on success
* @return self
*/
public function withContent($contents): self
{
Expand All @@ -121,14 +121,14 @@ public function reify(): string
/**
* Wrapper around verify()
*
* @param callable $callback
* @param string $description description of the pact and thus callback
* @param callable $callback
* @param false|string $description description of the pact and thus callback
*
* @throws \Exception
*
* @return bool
*/
public function verifyMessage($callback, $description = false): bool
public function verifyMessage(callable $callback, $description = false): bool
{
$this->setCallback($callback, $description);

Expand All @@ -139,9 +139,11 @@ public function verifyMessage($callback, $description = false): bool
* Verify the use of the pact by calling the callback
* It also calls finalize to write the pact
*
* @param string $description description of the pact and thus callback
* @param false|string $description description of the pact and thus callback
*
* @throws \Exception if callback is not set
*
* @return bool
*/
public function verify($description = false): bool
{
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPact/Consumer/Model/Message.php
Expand Up @@ -71,7 +71,7 @@ public function setProviderState(string $name, array $params = [], $overwrite =
/**
* @param string $name
* @param array $params
* @param array $overwrite - if true reset the entire state
* @param bool $overwrite - if true reset the entire state
*
* @return Message
*/
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPact/Standalone/Installer/InstallManager.php
Expand Up @@ -107,9 +107,9 @@ public static function uninstall()
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

* @param unknown $files
* @param mixed $files
*
* @throws IOException
* @throws \Exception
*/
public static function rmdir($files)
{
Expand Down
Expand Up @@ -79,7 +79,6 @@ private function download(string $fileName, string $tempFilePath): self
* @param string $destinationDir
*
* @return InstallerLinux
* @return string
*/
private function extract(string $sourceFile, string $destinationDir): self
{
Expand Down
1 change: 0 additions & 1 deletion src/PhpPact/Standalone/Installer/Service/InstallerMac.php
Expand Up @@ -79,7 +79,6 @@ private function download(string $fileName, string $tempFilePath): self
* @param string $destinationDir
*
* @return InstallerMac
* @return string
*/
private function extract(string $sourceFile, string $destinationDir): self
{
Expand Down
Expand Up @@ -85,7 +85,6 @@ private function download(string $fileName, string $tempFilePath): self
* @param string $destinationDir
*
* @return InstallerWindows
* @return string
*/
private function extract(string $sourceFile, string $destinationDir): self
{
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPact/Standalone/MockService/MockServer.php
Expand Up @@ -32,10 +32,10 @@ class MockServer
/**
* MockServer constructor.
*
* @param MockServerConfigInterface $config
* @param MockServerConfig $config
* @param null|MockServerHttpService $httpService
*/
public function __construct(MockServerConfigInterface $config, MockServerHttpService $httpService = null)
public function __construct(MockServerConfig $config, MockServerHttpService $httpService = null)
{
$this->config = $config;
$this->installManager = new InstallManager();
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPact/Standalone/MockService/MockServerConfig.php
Expand Up @@ -66,7 +66,7 @@ class MockServerConfig implements MockServerConfigInterface, PactConfigInterface
/**
* The pact specification version to use when writing the pact. Note that only versions 1 and 2 are currently supported.
*
* @var float
* @var string
*/
private $pactSpecificationVersion;

Expand Down
12 changes: 12 additions & 0 deletions src/PhpPact/Standalone/MockService/MockServerConfigInterface.php
Expand Up @@ -86,4 +86,16 @@ public function setHealthCheckTimeout($timeout): self;
* @return int
*/
public function getHealthCheckTimeout(): int;

/**
* @param int $seconds
*
* @return MockServerConfigInterface
*/
public function setHealthCheckRetrySec($seconds): self;

/**
* @return int
*/
public function getHealthCheckRetrySec(): int;
}
13 changes: 6 additions & 7 deletions src/PhpPact/Standalone/MockService/MockServerEnvConfig.php
Expand Up @@ -19,13 +19,12 @@ class MockServerEnvConfig extends MockServerConfig
*/
public function __construct()
{
$this
->setHost($this->parseEnv('PACT_MOCK_SERVER_HOST'))
->setPort($this->parseEnv('PACT_MOCK_SERVER_PORT'))
->setConsumer($this->parseEnv('PACT_CONSUMER_NAME'))
->setProvider($this->parseEnv('PACT_PROVIDER_NAME'))
->setPactDir($this->parseEnv('PACT_OUTPUT_DIR', false))
->setCors($this->parseEnv('PACT_CORS', false));
$this->setHost($this->parseEnv('PACT_MOCK_SERVER_HOST'));
$this->setPort((int) $this->parseEnv('PACT_MOCK_SERVER_PORT'));
$this->setConsumer($this->parseEnv('PACT_CONSUMER_NAME'));
$this->setProvider($this->parseEnv('PACT_PROVIDER_NAME'));
$this->setPactDir($this->parseEnv('PACT_OUTPUT_DIR', false));
$this->setCors($this->parseEnv('PACT_CORS', false));

if ($logDir = $this->parseEnv('PACT_LOG', false)) {
$this->setLog($logDir);
Expand Down
2 changes: 1 addition & 1 deletion src/PhpPact/Standalone/PactConfigInterface.php
Expand Up @@ -45,7 +45,7 @@ public function getPactDir();
public function setPactDir($pactDir): self;

/**
* @return float pact version
* @return string pact version
*/
public function getPactSpecificationVersion();

Expand Down
3 changes: 2 additions & 1 deletion src/PhpPact/Standalone/PactMessage/PactMessageConfig.php
Expand Up @@ -35,7 +35,7 @@ class PactMessageConfig implements PactConfigInterface
/**
* The pact specification version to use when writing the pact. Note that only versions 1 and 2 are currently supported.
*
* @var float
* @var string
*/
private $pactSpecificationVersion;

Expand All @@ -45,6 +45,7 @@ class PactMessageConfig implements PactConfigInterface
* @var string
*/
private $log;

/** @var string */
private $logLevel;

Expand Down
Expand Up @@ -150,12 +150,12 @@ public function getBrokerPassword();
public function setBrokerPassword(string $brokerPassword);

/**
* @return null|\string[] custom headers for the request to the provider such as authorization
* @return null|string[] custom headers for the request to the provider such as authorization
*/
public function getCustomProviderHeaders();

/**
* @param \string[] $customProviderHeaders custom headers for the requests to the provider such as authorization
* @param string[] $customProviderHeaders custom headers for the requests to the provider such as authorization
*
* @return VerifierConfigInterface
*/
Expand Down Expand Up @@ -218,7 +218,9 @@ public function getProcessTimeout(): int;
public function getProcessIdleTimeout(): int;

/**
* @return bool allow pacts which are in pending state to be verified without causing the overall task to fail
* @param bool $pending allow pacts which are in pending state to be verified without causing the overall task to fail
*
* @return VerifierConfigInterface
*/
public function setEnablePending(bool $pending): self;

Expand Down
4 changes: 2 additions & 2 deletions src/PhpPact/Standalone/ProviderVerifier/Verifier.php
Expand Up @@ -28,7 +28,7 @@ class Verifier
/** @var VerifierConfigInterface */
protected $config;

/** @var BrokerHttpClientInterface */
/** @var null|BrokerHttpClientInterface */
protected $brokerHttpClient;

/** @var InstallManager */
Expand Down Expand Up @@ -244,7 +244,7 @@ protected function verifyAction(array $arguments)
$this->verifierProcess->run($arguments, $this->processTimeout, $this->processIdleTimeout);
}

protected function getBrokerHttpClient(): BrokerHttpClient
protected function getBrokerHttpClient(): BrokerHttpClientInterface
{
if (!$this->brokerHttpClient) {
$user = $this->config->getBrokerUsername();
Expand Down
4 changes: 2 additions & 2 deletions src/PhpPact/Standalone/StubService/StubServer.php
Expand Up @@ -13,7 +13,7 @@
*/
class StubServer
{
/** @var StubServerConfig */
/** @var StubServerConfigInterface */
private $config;

/** @var InstallManager */
Expand All @@ -31,7 +31,7 @@ public function __construct(StubServerConfigInterface $config)
/**
* Start the Stub Server. Verify that it is running.
*
* @param $wait seconds to delay for the server to come up
* @param int $wait seconds to delay for the server to come up
*
* @throws Exception
*
Expand Down