From cc5a9ab6bfb17e9a3e4ab8406c74c6f492148204 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Mon, 9 Dec 2024 11:39:26 +0000 Subject: [PATCH 1/6] CI: test on PHP8.4 --- .github/workflows/php.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 9c36647..b13df1d 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -21,6 +21,7 @@ jobs: - "8.1" - "8.2" - "8.3" + - "8.4" steps: - uses: actions/checkout@v3 From 36fc43a1825b318c1b9cee2b71f725e21cf59d76 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Mon, 9 Dec 2024 11:39:40 +0000 Subject: [PATCH 2/6] PHP: use Deprecated annotation --- phpstan.neon.dist | 3 +++ src/Api/Credentials.php | 1 + src/Api/Customers.php | 3 +++ src/Api/Packages.php | 4 ++++ src/Api/Subrepositories.php | 2 ++ src/Client.php | 1 + 6 files changed, 14 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 46b0f47..ab9963e 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -3,3 +3,6 @@ parameters: paths: - src - tests + + ignoreErrors: + - '#Attribute class Deprecated does not exist#' diff --git a/src/Api/Credentials.php b/src/Api/Credentials.php index d7f5a73..5d7c103 100644 --- a/src/Api/Credentials.php +++ b/src/Api/Credentials.php @@ -43,6 +43,7 @@ public function create($description, $type, $domain, $username, $credential) /** * @deprecated Use edit instead */ + #[\Deprecated('Use Credentials::edit instead', '1.11.0')] public function update($credentialId, $type, $username, $credential) { return $this->edit($credentialId, $type, $username, $credential); diff --git a/src/Api/Customers.php b/src/Api/Customers.php index 27fbdbd..237d079 100644 --- a/src/Api/Customers.php +++ b/src/Api/Customers.php @@ -42,6 +42,7 @@ public function create($name, $accessToVersionControlSource = false, $urlName = /** * @deprecated Use edit instead */ + #[\Deprecated('Use Customers::edit instead', '1.11.0')] public function update($customerIdOrUrlName, array $customer) { return $this->edit($customerIdOrUrlName, $customer); @@ -80,6 +81,7 @@ public function showPackage($customerIdOrUrlName, $packageIdOrName) /** * @deprecated Use addOrEditPackages instead */ + #[\Deprecated('Use Customers::addOrEditPackages instead', '1.11.0')] public function addOrUpdatePackages($customerIdOrUrlName, array $packages) { return $this->addOrEditPackages($customerIdOrUrlName, $packages); @@ -99,6 +101,7 @@ public function addOrEditPackages($customerIdOrUrlName, array $packages) /** * @deprecated Use addOrEditPackages instead */ + #[\Deprecated('Use Customers::addOrEditPackages instead', '1.11.0')] public function addPackages($customerIdOrUrlName, array $packages) { return $this->addOrEditPackages($customerIdOrUrlName, $packages); diff --git a/src/Api/Packages.php b/src/Api/Packages.php index 0660c95..6a1f1a0 100644 --- a/src/Api/Packages.php +++ b/src/Api/Packages.php @@ -35,11 +35,13 @@ class Packages extends AbstractApi /** * @deprecated Use Packages::ORIGIN_PUBLIC_MIRROR instead */ + #[\Deprecated('Use Packages::ORIGIN_PUBLIC_MIRROR instead', '1.13.0')] const ORIGIN_PUBLIC_PROXY = self::ORIGIN_PUBLIC_MIRROR; /** * @deprecated Use Packages::ORIGIN_PRIVATE_MIRROR instead */ + #[\Deprecated('Use Packages::ORIGIN_PRIVATE_MIRROR instead', '1.13.0')] const ORIGIN_PRIVATE_PROXY = self::ORIGIN_PRIVATE_MIRROR; const AVAILABLE_ORIGINS = [self::ORIGIN_PUBLIC_MIRROR, self::ORIGIN_PRIVATE_MIRROR, self::ORIGIN_PRIVATE, 'public-proxy', 'private-proxy']; @@ -82,6 +84,7 @@ public function createArtifactPackage(array $artifactPackageFileIds, $defaultSub /** * @deprecated Use editVcsPackage instead */ + #[\Deprecated('Use Packages::editVcsPackage instead', '1.11.0')] public function updateVcsPackage($packageName, $url, $credentialId = null) { return $this->editVcsPackage($packageName, $url, $credentialId); @@ -104,6 +107,7 @@ public function editArtifactPackage($packageIdOrName, array $artifactPackageFile /** * @deprecated Use editCustomPackage instead */ + #[\Deprecated('Use Packages::editCustomPackage instead', '1.11.0')] public function updateCustomPackage($packageName, $customJson, $credentialId = null) { return $this->editCustomPackage($packageName, $customJson, $credentialId); diff --git a/src/Api/Subrepositories.php b/src/Api/Subrepositories.php index 9185bad..075825b 100644 --- a/src/Api/Subrepositories.php +++ b/src/Api/Subrepositories.php @@ -41,6 +41,7 @@ public function listTeams($subrepositoryName) /** * @deprecated Use addOrEditTeams instead */ + #[\Deprecated('Use Subrepositories::addOrEditTeams instead', '1.10.0')] public function addOrUpdateTeams($subrepositoryName, array $teams) { return $this->addOrEditTeams($subrepositoryName, $teams); @@ -69,6 +70,7 @@ public function removeTeam($subrepositoryName, $teamId) /** * @deprecated use packages()->all() */ + #[\Deprecated('Use Subrepositories::packages()->all() instead', '1.16.1')] public function listPackages($subrepositoryName) { return $this->packages()->all($subrepositoryName); diff --git a/src/Client.php b/src/Client.php index bd25209..24be3a2 100644 --- a/src/Client.php +++ b/src/Client.php @@ -72,6 +72,7 @@ public function customers() /** * @deprecated Use Client::subrepositories instead */ + #[\Deprecated('Use Client::subrepositories instead', '1.16.1')] public function projects() { return new Api\Subrepositories($this, $this->responseMediator); From bdc90e9f49301b184fc3f0cef06572f91abe7786 Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Mon, 9 Dec 2024 11:51:30 +0000 Subject: [PATCH 3/6] PHP: use SensitiveParameter annotation --- src/Client.php | 8 ++++++-- src/HttpClient/Plugin/RequestSignature.php | 8 ++++++-- src/WebhookSignature.php | 6 ++++-- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/src/Client.php b/src/Client.php index 24be3a2..e234c3e 100644 --- a/src/Client.php +++ b/src/Client.php @@ -48,8 +48,12 @@ public function __construct(HttpPluginClientBuilder $httpClientBuilder = null, $ * @param string $key * @param string $secret */ - public function authenticate($key, $secret) - { + public function authenticate( + #[\SensitiveParameter] + $key, + #[\SensitiveParameter] + $secret + ) { $this->httpClientBuilder->removePlugin(RequestSignature::class); $this->httpClientBuilder->addPlugin(new RequestSignature($key, $secret)); } diff --git a/src/HttpClient/Plugin/RequestSignature.php b/src/HttpClient/Plugin/RequestSignature.php index 3988c30..c313778 100644 --- a/src/HttpClient/Plugin/RequestSignature.php +++ b/src/HttpClient/Plugin/RequestSignature.php @@ -25,8 +25,12 @@ class RequestSignature implements Plugin * @param string $key * @param string $secret */ - public function __construct($key, $secret) - { + public function __construct( + #[\SensitiveParameter] + $key, + #[\SensitiveParameter] + $secret + ) { if (!$key || !$secret) { throw new \InvalidArgumentException('$key and $secret must be set'); } diff --git a/src/WebhookSignature.php b/src/WebhookSignature.php index b1782b6..5434183 100644 --- a/src/WebhookSignature.php +++ b/src/WebhookSignature.php @@ -14,8 +14,10 @@ class WebhookSignature /** @var string */ private $secret; - public function __construct($secret) - { + public function __construct( + #[\SensitiveParameter] + $secret + ) { $this->secret = $secret; } From 3e49b43d3c19124d142f132237dfa8d6d1c2437d Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Mon, 9 Dec 2024 11:53:07 +0000 Subject: [PATCH 4/6] PHPStan: ignore unmatched errors --- phpstan.neon.dist | 2 ++ 1 file changed, 2 insertions(+) diff --git a/phpstan.neon.dist b/phpstan.neon.dist index ab9963e..b1a7563 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -1,5 +1,7 @@ parameters: level: 5 + reportUnmatchedIgnoredErrors: false + paths: - src - tests From 8afe5aa1d9a403c7cc2e84d5c1a649ad36306b3c Mon Sep 17 00:00:00 2001 From: Stephan Vock Date: Mon, 9 Dec 2024 11:57:32 +0000 Subject: [PATCH 5/6] PHP 8.4 fix implicitly nullable via default value null --- src/Api/AbstractApi.php | 4 ++-- src/Client.php | 2 +- src/Exception/HttpTransportException.php | 2 +- src/HttpClient/Plugin/ExceptionThrower.php | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Api/AbstractApi.php b/src/Api/AbstractApi.php index d3ff630..845260f 100644 --- a/src/Api/AbstractApi.php +++ b/src/Api/AbstractApi.php @@ -19,10 +19,10 @@ abstract class AbstractApi /** @var ResponseMediator */ private $responseMediator; - public function __construct(Client $client, ResponseMediator $responseMediator = null) + public function __construct(Client $client, ?ResponseMediator $responseMediator = null) { $this->client = $client; - $this->responseMediator = $responseMediator ? $responseMediator : new ResponseMediator(); + $this->responseMediator = $responseMediator ? : new ResponseMediator(); } /** diff --git a/src/Client.php b/src/Client.php index e234c3e..381423a 100644 --- a/src/Client.php +++ b/src/Client.php @@ -25,7 +25,7 @@ class Client private $responseMediator; /** @param string $privatePackagistUrl */ - public function __construct(HttpPluginClientBuilder $httpClientBuilder = null, $privatePackagistUrl = null, ResponseMediator $responseMediator = null) + public function __construct(?HttpPluginClientBuilder $httpClientBuilder = null, $privatePackagistUrl = null, ?ResponseMediator $responseMediator = null) { $this->httpClientBuilder = $builder = $httpClientBuilder ?: new HttpPluginClientBuilder(); $privatePackagistUrl = $privatePackagistUrl ? : 'https://packagist.com'; diff --git a/src/Exception/HttpTransportException.php b/src/Exception/HttpTransportException.php index 52c3546..2f5e423 100644 --- a/src/Exception/HttpTransportException.php +++ b/src/Exception/HttpTransportException.php @@ -15,7 +15,7 @@ class HttpTransportException extends RuntimeException { private $requestUri; - public function __construct($message = "", $code = 0, $requestUri = "", Throwable $previous = null) + public function __construct($message = "", $code = 0, $requestUri = "", ?Throwable $previous = null) { $this->requestUri = $requestUri; parent::__construct($message, $code, $previous); diff --git a/src/HttpClient/Plugin/ExceptionThrower.php b/src/HttpClient/Plugin/ExceptionThrower.php index 1dd1ae9..96180b6 100644 --- a/src/HttpClient/Plugin/ExceptionThrower.php +++ b/src/HttpClient/Plugin/ExceptionThrower.php @@ -24,9 +24,9 @@ class ExceptionThrower implements Plugin /** @var ResponseMediator */ private $responseMediator; - public function __construct(ResponseMediator $responseMediator = null) + public function __construct(?ResponseMediator $responseMediator = null) { - $this->responseMediator = $responseMediator ? $responseMediator : new ResponseMediator(); + $this->responseMediator = $responseMediator ? : new ResponseMediator(); } protected function doHandleRequest(RequestInterface $request, callable $next, callable $first) From 6478f92404ddfdd282ce45dc82ee29cca97c185b Mon Sep 17 00:00:00 2001 From: Stephan Date: Mon, 9 Dec 2024 14:32:25 +0000 Subject: [PATCH 6/6] Update src/Api/AbstractApi.php Co-authored-by: Philipp Scheit --- src/Api/AbstractApi.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Api/AbstractApi.php b/src/Api/AbstractApi.php index 845260f..a923eef 100644 --- a/src/Api/AbstractApi.php +++ b/src/Api/AbstractApi.php @@ -22,7 +22,7 @@ abstract class AbstractApi public function __construct(Client $client, ?ResponseMediator $responseMediator = null) { $this->client = $client; - $this->responseMediator = $responseMediator ? : new ResponseMediator(); + $this->responseMediator = $responseMediator ?: new ResponseMediator(); } /**