Skip to content

Commit

Permalink
Merge pull request #81 from packagist/php84
Browse files Browse the repository at this point in the history
PHP 8.4 support and use new attributes
  • Loading branch information
glaubinix authored Dec 9, 2024
2 parents 7b315a0 + 6478f92 commit 2f24c2a
Show file tree
Hide file tree
Showing 12 changed files with 39 additions and 12 deletions.
1 change: 1 addition & 0 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- uses: actions/checkout@v3
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
parameters:
level: 5
reportUnmatchedIgnoredErrors: false

paths:
- src
- tests

ignoreErrors:
- '#Attribute class Deprecated does not exist#'
4 changes: 2 additions & 2 deletions src/Api/AbstractApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/Api/Credentials.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 3 additions & 0 deletions src/Api/Customers.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions src/Api/Packages.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/Api/Subrepositories.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
11 changes: 8 additions & 3 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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));
}
Expand All @@ -72,6 +76,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);
Expand Down
2 changes: 1 addition & 1 deletion src/Exception/HttpTransportException.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions src/HttpClient/Plugin/ExceptionThrower.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 6 additions & 2 deletions src/HttpClient/Plugin/RequestSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
Expand Down
6 changes: 4 additions & 2 deletions src/WebhookSignature.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ class WebhookSignature
/** @var string */
private $secret;

public function __construct($secret)
{
public function __construct(
#[\SensitiveParameter]
$secret
) {
$this->secret = $secret;
}

Expand Down

0 comments on commit 2f24c2a

Please sign in to comment.