From de79190e6f2bb667c2ab9ad3d94815c20f218ba8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Gertz?= Date: Thu, 29 Feb 2024 14:12:42 +0100 Subject: [PATCH 1/1] Php 8.x constructor style Strict types --- Package/PathPackage.php | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/Package/PathPackage.php b/Package/PathPackage.php index 8b53136..c202b19 100644 --- a/Package/PathPackage.php +++ b/Package/PathPackage.php @@ -21,21 +21,20 @@ use Rapsys\PackBundle\Context\NullContext; * {@inheritdoc} */ class PathPackage extends Package { - //The base path - protected $basePath; - - //The base url - protected $baseUrl; + /** + * The base url + */ + protected string $baseUrl; /** * {@inheritdoc} */ - public function __construct(string $basePath, VersionStrategyInterface $versionStrategy, ContextInterface $context = null) { + public function __construct(protected string $basePath, protected VersionStrategyInterface $versionStrategy, protected ?ContextInterface $context = null) { //Without context use a null context - $context = $context ?? new NullContext(); + $this->context = $this->context ?? new NullContext(); //Call parent constructor - parent::__construct($versionStrategy, $context); + parent::__construct($this->versionStrategy, $this->context); //Without base path if (empty($basePath)) { @@ -54,7 +53,7 @@ class PathPackage extends Package { } //Set base url - $this->baseUrl = $context->getBaseUrl(); + $this->baseUrl = $this->context->getBaseUrl(); } /** @@ -69,7 +68,7 @@ class PathPackage extends Package { * * {@inheritdoc} */ - public function getUrl($path): string { + public function getUrl(string $path): string { //Match url starting with a bundle name if (preg_match('%^@([A-Z][a-zA-Z]*?)(?:Bundle/Resources/public)?/(.*)$%', $path, $matches)) { //Handle empty or without replacement pattern basePath -- 2.41.1