From 6777732c1026aea4f73cb05d175dd522380c1afb Mon Sep 17 00:00:00 2001 From: Linnea Date: Fri, 6 Jan 2023 13:33:06 -0500 Subject: [PATCH 1/8] Updating to php 8.1 and craft 4 --- composer.json | 10 ++++++-- src/EventRegistrar.php | 17 ++++++------- src/Plugin.php | 29 ++++++++--------------- src/PurgerFactory.php | 5 ++-- src/behaviors/CacheControlBehavior.php | 6 ++--- src/behaviors/TagHeaderBehavior.php | 2 -- src/drivers/AbstractPurger.php | 7 ++---- src/drivers/CachePurgeInterface.php | 4 ---- src/drivers/Cloudflare.php | 17 ++++--------- src/drivers/Dummy.php | 4 ---- src/drivers/Fastly.php | 18 ++++++-------- src/drivers/Keycdn.php | 20 +++++----------- src/drivers/Varnish.php | 5 ---- src/exceptions/CloudflareApiException.php | 4 +--- src/exceptions/FastlyApiException.php | 2 -- src/exceptions/KeycdnApiException.php | 2 -- src/models/Settings.php | 4 +--- 17 files changed, 52 insertions(+), 104 deletions(-) diff --git a/composer.json b/composer.json index 913f2a1..bf12a5c 100644 --- a/composer.json +++ b/composer.json @@ -24,11 +24,11 @@ } ], "require": { - "craftcms/cms": "^3.2.0", + "craftcms/cms": "^4.0.0", "guzzlehttp/guzzle": "^6.5.5|^7.2.0" }, "require-dev": { - "vimeo/psalm": "^4.4" + "vimeo/psalm": "^4.4", }, "autoload": { "psr-4": { @@ -45,5 +45,11 @@ "hasCpSettings": false, "hasCpSection": false, "changelogUrl": "https://raw.githubusercontent.com/ostark/upper/master/CHANGELOG.md" + }, + "config": { + "allow-plugins": { + "yiisoft/yii2-composer": true, + "craftcms/plugin-installer": true + } } } diff --git a/src/EventRegistrar.php b/src/EventRegistrar.php index 156e44c..a8c39be 100644 --- a/src/EventRegistrar.php +++ b/src/EventRegistrar.php @@ -76,7 +76,7 @@ public static function registerFrontendEvents() Event::on(ElementQuery::class, ElementQuery::EVENT_AFTER_POPULATE_ELEMENT, function (PopulateElementEvent $event) { // Don't collect MatrixBlock and User elements for now - if (!Plugin::getInstance()->getSettings()->isCachableElement(get_class($event->element))) { + if (!Plugin::getInstance()->getSettings()->isCachableElement($event->element::class)) { return; } @@ -120,8 +120,8 @@ public static function registerFrontendEvents() $response->setTagHeader($settings->getTagHeaderName(), $maxedTags, $settings->getHeaderTagDelimiter()); // Flag truncation - if (count($tags) > count($maxedTags)) { - $headers->set(Plugin::TRUNCATED_HEADER_NAME, count($tags) - count($maxedTags)); + if ((is_countable($tags) ? count($tags) : 0) > (is_countable($maxedTags) ? count($maxedTags) : 0)) { + $headers->set(Plugin::TRUNCATED_HEADER_NAME, (is_countable($tags) ? count($tags) : 0) - (is_countable($maxedTags) ? count($maxedTags) : 0)); } $response->setSharedMaxAge($maxAge); @@ -172,7 +172,7 @@ public static function registerFallback() // fulltext or array $tags = \Craft::$app->getDb()->getIsMysql() ? implode(" ", $event->tags) - : str_replace(['[', ']'], ['{', '}'], json_encode($event->tags) ?: '[]'); + : str_replace(['[', ']'], ['{', '}'], json_encode($event->tags, JSON_THROW_ON_ERROR) ?: '[]'); // in order to have a unique (collitions are possible) identifier by url with a fixed length $urlHash = md5($event->requestUrl); @@ -192,12 +192,12 @@ public static function registerFallback() 'urlHash' => $urlHash, 'url' => $event->requestUrl, 'tags' => $tags, - 'headers' => json_encode($event->headers), + 'headers' => json_encode($event->headers, JSON_THROW_ON_ERROR), 'siteId' => \Craft::$app->getSites()->currentSite->id ] ) ->execute(); - } catch (\Exception $e) { + } catch (\Exception) { \Craft::warning("Failed to register fallback.", "upper"); } @@ -206,9 +206,6 @@ public static function registerFallback() } - /** - * @param \yii\base\Event $event - */ protected static function handleUpdateEvent(Event $event) { $tags = []; @@ -216,7 +213,7 @@ protected static function handleUpdateEvent(Event $event) if ($event instanceof ElementEvent) { - if (!Plugin::getInstance()->getSettings()->isCachableElement(get_class($event->element))) { + if (!Plugin::getInstance()->getSettings()->isCachableElement($event->element::class)) { return; } diff --git a/src/Plugin.php b/src/Plugin.php index 255e0fa..95e2f5c 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -18,28 +18,28 @@ class Plugin extends BasePlugin { // Event names - const EVENT_AFTER_SET_TAG_HEADER = 'upper_after_set_tag_header'; - const EVENT_BEFORE_PURGE = 'upper_before_purge'; - const EVENT_AFTER_PURGE = 'upper_after_purge'; + final const EVENT_AFTER_SET_TAG_HEADER = 'upper_after_set_tag_header'; + final const EVENT_BEFORE_PURGE = 'upper_before_purge'; + final const EVENT_AFTER_PURGE = 'upper_after_purge'; // Tag prefixes - const TAG_PREFIX_ELEMENT = 'el'; - const TAG_PREFIX_SECTION = 'se'; - const TAG_PREFIX_STRUCTURE = 'st'; + final const TAG_PREFIX_ELEMENT = 'el'; + final const TAG_PREFIX_SECTION = 'se'; + final const TAG_PREFIX_STRUCTURE = 'st'; // Mapping element properties <> tag prefixes - const ELEMENT_PROPERTY_MAP = [ + final const ELEMENT_PROPERTY_MAP = [ 'id' => self::TAG_PREFIX_ELEMENT, 'sectionId' => self::TAG_PREFIX_SECTION, 'structureId' => self::TAG_PREFIX_STRUCTURE ]; // DB - const CACHE_TABLE = '{{%upper_cache}}'; + final const CACHE_TABLE = '{{%upper_cache}}'; // Header - const INFO_HEADER_NAME = 'X-UPPER-CACHE'; - const TRUNCATED_HEADER_NAME = 'X-UPPER-CACHE-TRUNCATED'; + final const INFO_HEADER_NAME = 'X-UPPER-CACHE'; + final const TRUNCATED_HEADER_NAME = 'X-UPPER-CACHE-TRUNCATED'; public $schemaVersion = '1.0.1'; @@ -79,21 +79,12 @@ public function init() \Craft::$app->getView()->registerTwigExtension(new TwigExtension); } - // ServiceLocators - // ========================================================================= - - /** - * @return \ostark\upper\drivers\CachePurgeInterface - */ public function getPurger(): CachePurgeInterface { return $this->get('purger'); } - /** - * @return \ostark\upper\TagCollection - */ public function getTagCollection(): TagCollection { /* @var \ostark\upper\TagCollection $collection */ diff --git a/src/PurgerFactory.php b/src/PurgerFactory.php index 6f9dfb2..52c4c19 100644 --- a/src/PurgerFactory.php +++ b/src/PurgerFactory.php @@ -5,10 +5,9 @@ class PurgerFactory extends Component { - const DRIVERS_NAMESPACE = 'ostark\upper\drivers'; + final const DRIVERS_NAMESPACE = 'ostark\upper\drivers'; /** - * @param array $config * * @return \ostark\upper\drivers\CachePurgeInterface * @throws \yii\base\InvalidConfigException @@ -26,7 +25,7 @@ public static function create(array $config = []) } $driverConfig = $config['drivers'][$config['driver']]; - $driverClass = $driverConfig['class'] ?? self::DRIVERS_NAMESPACE . '\\' . ucfirst($config['driver']); + $driverClass = $driverConfig['class'] ?? self::DRIVERS_NAMESPACE . '\\' . ucfirst((string) $config['driver']); // tagHeaderName and tagHeaderDelimiter are not relevant to the Purger unset($driverConfig['tagHeaderName'], $driverConfig['tagHeaderDelimiter']); diff --git a/src/behaviors/CacheControlBehavior.php b/src/behaviors/CacheControlBehavior.php index 93c9f38..02b515d 100644 --- a/src/behaviors/CacheControlBehavior.php +++ b/src/behaviors/CacheControlBehavior.php @@ -23,7 +23,7 @@ class CacheControlBehavior extends Behavior * @param string $key The Cache-Control directive name * @param mixed $value The Cache-Control directive value */ - public function addCacheControlDirective(string $key, $value = true) + public function addCacheControlDirective(string $key, mixed $value = true) { $this->cacheControl[$key] = $value; $this->owner->getHeaders()->set('Cache-Control', $this->getCacheControlHeader()); @@ -147,13 +147,13 @@ public function setCacheControlDirectiveFromString(string $value = null) protected function getCacheControlHeader() { - $parts = array(); + $parts = []; ksort($this->cacheControl); foreach ($this->cacheControl as $key => $value) { if (true === $value) { $parts[] = $key; } else { - if (preg_match('#[^a-zA-Z0-9._-]#', $value)) { + if (preg_match('#[^a-zA-Z0-9._-]#', (string) $value)) { $value = '"' . $value . '"'; } $parts[] = "$key=$value"; diff --git a/src/behaviors/TagHeaderBehavior.php b/src/behaviors/TagHeaderBehavior.php index bd0cc3e..d0020cf 100644 --- a/src/behaviors/TagHeaderBehavior.php +++ b/src/behaviors/TagHeaderBehavior.php @@ -14,8 +14,6 @@ class TagHeaderBehavior extends Behavior /** * Simply tag * - * @param string $name - * @param array $tags * @param string|null $delimiter * * @return bool diff --git a/src/drivers/AbstractPurger.php b/src/drivers/AbstractPurger.php index 826b159..156632b 100644 --- a/src/drivers/AbstractPurger.php +++ b/src/drivers/AbstractPurger.php @@ -25,8 +25,6 @@ public function __construct($config) /** - * @param string $tag - * * @return bool */ public function purgeUrlsByTag(string $tag) @@ -39,7 +37,7 @@ public function purgeUrlsByTag(string $tag) return true; } - } catch (Exception $e) { + } catch (Exception) { \Craft::warning("Failed to purge '$tag'.", "upper"); } @@ -79,7 +77,7 @@ public function getTaggedUrls($tag) ->createCommand($sql) ->queryAll(); - if (count($results) === 0) { + if ((is_countable($results) ? count($results) : 0) === 0) { return []; } @@ -88,7 +86,6 @@ public function getTaggedUrls($tag) } /** - * @param array $uids * * @return int * @throws \yii\db\Exception diff --git a/src/drivers/CachePurgeInterface.php b/src/drivers/CachePurgeInterface.php index ac9cc42..a2aae84 100644 --- a/src/drivers/CachePurgeInterface.php +++ b/src/drivers/CachePurgeInterface.php @@ -9,15 +9,11 @@ interface CachePurgeInterface { /** - * @param string $tag - * * @return bool */ public function purgeTag(string $tag); /** - * @param array $urls - * * @return bool */ public function purgeUrls(array $urls); diff --git a/src/drivers/Cloudflare.php b/src/drivers/Cloudflare.php index 6e5ab33..57d1da5 100644 --- a/src/drivers/Cloudflare.php +++ b/src/drivers/Cloudflare.php @@ -15,9 +15,9 @@ class Cloudflare extends AbstractPurger implements CachePurgeInterface /** * Cloudflare API endpoint */ - const API_ENDPOINT = 'https://api.cloudflare.com/client/v4/'; + final const API_ENDPOINT = 'https://api.cloudflare.com/client/v4/'; - const MAX_URLS_PER_PURGE = 30; + final const MAX_URLS_PER_PURGE = 30; public $apiKey; @@ -31,8 +31,6 @@ class Cloudflare extends AbstractPurger implements CachePurgeInterface /** - * @param string $tag - * * @return bool */ public function purgeTag(string $tag) @@ -48,21 +46,18 @@ public function purgeTag(string $tag) } /** - * @param array $urls * * @return bool * @throws \ostark\upper\exceptions\CloudflareApiException */ public function purgeUrls(array $urls) { - if (strpos($this->domain, 'http') !== 0) { + if (!str_starts_with((string) $this->domain, 'http')) { throw new \InvalidArgumentException("'domain' must include the protocol, e.g. https://www.foo.com"); } // prefix urls with domain - $files = array_map(function($url) { - return rtrim($this->domain, '/') . $url; - }, $urls); + $files = array_map(fn($url) => rtrim((string) $this->domain, '/') . $url, $urls); // Chunk larger collections to meet the API constraints foreach (array_chunk($files, self::MAX_URLS_PER_PURGE) as $fileGroup) { @@ -95,13 +90,11 @@ public function purgeAll() /** * @param string $method HTTP verb - * @param string $type - * @param array $params * * @return bool * @throws \ostark\upper\exceptions\CloudflareApiException */ - protected function sendRequest($method = 'DELETE', string $type, array $params = []) + protected function sendRequest(string $type, $method = 'DELETE', array $params = []) { $client = $this->getClient(); diff --git a/src/drivers/Dummy.php b/src/drivers/Dummy.php index 1f3796b..9503598 100644 --- a/src/drivers/Dummy.php +++ b/src/drivers/Dummy.php @@ -14,8 +14,6 @@ class Dummy extends AbstractPurger implements CachePurgeInterface public $logPurgeActions = true; /** - * @param string $tag - * * @return bool */ public function purgeTag(string $tag) @@ -31,8 +29,6 @@ public function purgeTag(string $tag) /** - * @param array $urls - * * @return bool */ public function purgeUrls(array $urls) diff --git a/src/drivers/Fastly.php b/src/drivers/Fastly.php index 90a64d5..0028f59 100644 --- a/src/drivers/Fastly.php +++ b/src/drivers/Fastly.php @@ -27,7 +27,7 @@ class Fastly extends AbstractPurger implements CachePurgeInterface /** * Fastly API endpoint */ - const API_ENDPOINT = 'https://api.fastly.com'; + final const API_ENDPOINT = 'https://api.fastly.com'; /** * @var string @@ -52,13 +52,12 @@ class Fastly extends AbstractPurger implements CachePurgeInterface /** * Purge cache by tag * - * @param string $tag * * @return bool */ public function purgeTag(string $tag) { - return $this->sendRequest('POST', 'purge', [ + return $this->sendRequest('purge', 'POST', [ 'Surrogate-Key' => $tag ] ); @@ -67,22 +66,21 @@ public function purgeTag(string $tag) /** * Purge cache by urls * - * @param array $urls * * @return bool */ public function purgeUrls(array $urls) { - if (strpos($this->domain, 'http') === false) { + if (!str_contains($this->domain, 'http')) { throw new \InvalidArgumentException("'domain' is not configured for fastly driver"); } - if (strpos($this->domain, 'http') !== 0) { + if (!str_starts_with($this->domain, 'http')) { throw new \InvalidArgumentException("'domain' must include the protocol, e.g. http://www.foo.com"); } foreach ($urls as $url) { - if (!$this->sendRequest('PURGE', $this->domain . $url)) { + if (!$this->sendRequest($this->domain . $url, 'PURGE')) { return false; } } @@ -98,20 +96,18 @@ public function purgeUrls(array $urls) */ public function purgeAll() { - return $this->sendRequest('POST', 'purge_all'); + return $this->sendRequest('purge_all', 'POST'); } /** * Send API call * * @param string $method HTTP verb - * @param string $uri - * @param array $headers * * @return bool * @throws \ostark\upper\exceptions\FastlyApiException */ - protected function sendRequest(string $method = 'PURGE', string $uri, array $headers = []) + protected function sendRequest(string $uri, string $method = 'PURGE', array $headers = []) { $client = new Client([ 'base_uri' => self::API_ENDPOINT, diff --git a/src/drivers/Keycdn.php b/src/drivers/Keycdn.php index 1ff8b45..cf787d6 100644 --- a/src/drivers/Keycdn.php +++ b/src/drivers/Keycdn.php @@ -14,7 +14,7 @@ class Keycdn extends AbstractPurger implements CachePurgeInterface /** * KeyCDN API endpoint */ - const API_ENDPOINT = 'https://api.keycdn.com/'; + final const API_ENDPOINT = 'https://api.keycdn.com/'; public $apiKey; @@ -24,31 +24,25 @@ class Keycdn extends AbstractPurger implements CachePurgeInterface /** - * @param string $tag - * * @return bool */ public function purgeTag(string $tag) { - return $this->sendRequest('DELETE', 'purgetag', [ + return $this->sendRequest('purgetag', 'DELETE', [ 'tags' => [$tag] ] ); } /** - * @param array $urls - * * @return bool */ public function purgeUrls(array $urls) { // prefix urls - $zoneUrls = array_map(function ($url) { - return $this->zoneUrl . $url; - }, $urls); + $zoneUrls = array_map(fn($url) => $this->zoneUrl . $url, $urls); - return $this->sendRequest('DELETE', 'purgeurl', [ + return $this->sendRequest('purgeurl', 'DELETE', [ 'urls' => $zoneUrls ] ); @@ -60,19 +54,17 @@ public function purgeUrls(array $urls) */ public function purgeAll() { - return $this->sendRequest('GET', 'purge', []); + return $this->sendRequest('purge', 'GET', []); } /** * @param string $method HTTP verb - * @param string $type - * @param array $params * * @return bool * @throws \ostark\upper\exceptions\KeycdnApiException */ - protected function sendRequest($method = 'DELETE', string $type, array $params = []) + protected function sendRequest(string $type, $method = 'DELETE', array $params = []) { $token = base64_encode("{$this->apiKey}:"); $client = new Client([ diff --git a/src/drivers/Varnish.php b/src/drivers/Varnish.php index b9da0ec..6280fc3 100644 --- a/src/drivers/Varnish.php +++ b/src/drivers/Varnish.php @@ -26,9 +26,6 @@ class Varnish extends AbstractPurger implements CachePurgeInterface */ public $headers = []; - /** - * @param string $tag - */ public function purgeTag(string $tag) { if ($this->useLocalTags) { @@ -42,8 +39,6 @@ public function purgeTag(string $tag) } /** - * @param array $urls - * * @return bool */ public function purgeUrls(array $urls) diff --git a/src/exceptions/CloudflareApiException.php b/src/exceptions/CloudflareApiException.php index bf31518..4024f2f 100644 --- a/src/exceptions/CloudflareApiException.php +++ b/src/exceptions/CloudflareApiException.php @@ -11,9 +11,7 @@ public function __construct(string $message = "", int $code = 0, \Throwable $pre } /** - * @param \Psr\Http\Message\RequestInterface $request * @param \Psr\Http\Message\ResponseInterface|null $response - * * @return static */ public static function create(RequestInterface $request, ResponseInterface $response = null) @@ -33,7 +31,7 @@ public static function create(RequestInterface $request, ResponseInterface $resp // Error message - if (isset($json->errors) && count($json->errors) >= 1) { + if (isset($json->errors) && (is_countable($json->errors) ? count($json->errors) : 0) >= 1) { return new static($json->errors[0]->message . ", uri: '$uri'", $json->errors[0]->code); } diff --git a/src/exceptions/FastlyApiException.php b/src/exceptions/FastlyApiException.php index 5a1c9e1..fbc5fb6 100644 --- a/src/exceptions/FastlyApiException.php +++ b/src/exceptions/FastlyApiException.php @@ -11,9 +11,7 @@ public function __construct(string $message = "", int $code = 0, \Throwable $pre } /** - * @param \Psr\Http\Message\RequestInterface $request * @param \Psr\Http\Message\ResponseInterface|null $response - * * @return static */ public static function create(RequestInterface $request, ResponseInterface $response = null) diff --git a/src/exceptions/KeycdnApiException.php b/src/exceptions/KeycdnApiException.php index c5c1f7f..f37dd2b 100644 --- a/src/exceptions/KeycdnApiException.php +++ b/src/exceptions/KeycdnApiException.php @@ -11,9 +11,7 @@ public function __construct(string $message = "", int $code = 0, \Throwable $pre } /** - * @param \Psr\Http\Message\RequestInterface $request * @param \Psr\Http\Message\ResponseInterface|null $response - * * @return static */ public static function create(RequestInterface $request, ResponseInterface $response = null) diff --git a/src/models/Settings.php b/src/models/Settings.php index 047ced7..6032081 100644 --- a/src/models/Settings.php +++ b/src/models/Settings.php @@ -77,7 +77,7 @@ class Settings extends Model * * @return array */ - public function rules() + public function rules(): array { return [ [['driver', 'drivers','keyPrefix'], 'required'], @@ -126,8 +126,6 @@ public function getNoCacheElements() } /** - * @param string $class - * * @return bool */ public function isCachableElement(string $class) From 28ae4eb6a324974325325ca15a38e600662907d4 Mon Sep 17 00:00:00 2001 From: Linnea Date: Fri, 6 Jan 2023 13:33:22 -0500 Subject: [PATCH 2/8] Fixing typo in composer.json --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index bf12a5c..f993aa1 100644 --- a/composer.json +++ b/composer.json @@ -28,7 +28,7 @@ "guzzlehttp/guzzle": "^6.5.5|^7.2.0" }, "require-dev": { - "vimeo/psalm": "^4.4", + "vimeo/psalm": "^4.4" }, "autoload": { "psr-4": { From c7b1c920e7ee16e1dda9761c7753a9e68793ca3c Mon Sep 17 00:00:00 2001 From: Linnea Date: Fri, 6 Jan 2023 16:11:20 -0500 Subject: [PATCH 3/8] PHP 8.1 updates --- src/Plugin.php | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 95e2f5c..0c5b854 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -18,30 +18,30 @@ class Plugin extends BasePlugin { // Event names - final const EVENT_AFTER_SET_TAG_HEADER = 'upper_after_set_tag_header'; - final const EVENT_BEFORE_PURGE = 'upper_before_purge'; - final const EVENT_AFTER_PURGE = 'upper_after_purge'; + const EVENT_AFTER_SET_TAG_HEADER = 'upper_after_set_tag_header'; + const EVENT_BEFORE_PURGE = 'upper_before_purge'; + const EVENT_AFTER_PURGE = 'upper_after_purge'; // Tag prefixes - final const TAG_PREFIX_ELEMENT = 'el'; - final const TAG_PREFIX_SECTION = 'se'; - final const TAG_PREFIX_STRUCTURE = 'st'; + const TAG_PREFIX_ELEMENT = 'el'; + const TAG_PREFIX_SECTION = 'se'; + const TAG_PREFIX_STRUCTURE = 'st'; // Mapping element properties <> tag prefixes - final const ELEMENT_PROPERTY_MAP = [ + const ELEMENT_PROPERTY_MAP = [ 'id' => self::TAG_PREFIX_ELEMENT, 'sectionId' => self::TAG_PREFIX_SECTION, 'structureId' => self::TAG_PREFIX_STRUCTURE ]; // DB - final const CACHE_TABLE = '{{%upper_cache}}'; + const CACHE_TABLE = '{{%upper_cache}}'; // Header - final const INFO_HEADER_NAME = 'X-UPPER-CACHE'; - final const TRUNCATED_HEADER_NAME = 'X-UPPER-CACHE-TRUNCATED'; + const INFO_HEADER_NAME = 'X-UPPER-CACHE'; + const TRUNCATED_HEADER_NAME = 'X-UPPER-CACHE-TRUNCATED'; - public $schemaVersion = '1.0.1'; + public string $schemaVersion = '1.0.1'; /** From a3879a52f3a18c5e5356a20f3ecb9ef99ea3ad03 Mon Sep 17 00:00:00 2001 From: Linnea Date: Fri, 6 Jan 2023 16:14:02 -0500 Subject: [PATCH 4/8] Updating declarations for php 8.1 --- src/Plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index 0c5b854..e97127e 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -103,7 +103,7 @@ public function getTagCollection(): TagCollection * * @return \craft\base\Model|null */ - protected function createSettingsModel() + protected function createSettingsModel():\craft\base\Model|null { return new Settings(); } @@ -113,7 +113,7 @@ protected function createSettingsModel() * Is called after the plugin is installed. * Copies example config to project's config folder */ - protected function afterInstall() + protected function afterInstall():void { $configSourceFile = __DIR__ . DIRECTORY_SEPARATOR . 'config.example.php'; $configTargetFile = \Craft::$app->getConfig()->configDir . DIRECTORY_SEPARATOR . $this->handle . '.php'; From 41077b7a134e4951931ef8204193ab367739760b Mon Sep 17 00:00:00 2001 From: Linnea Date: Fri, 6 Jan 2023 16:16:49 -0500 Subject: [PATCH 5/8] Updating declarations for php 8.1 --- src/Plugin.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Plugin.php b/src/Plugin.php index e97127e..d920ceb 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -103,7 +103,7 @@ public function getTagCollection(): TagCollection * * @return \craft\base\Model|null */ - protected function createSettingsModel():\craft\base\Model|null + protected function createSettingsModel(): \craft\base\Model|null { return new Settings(); } @@ -113,7 +113,7 @@ protected function createSettingsModel():\craft\base\Model|null * Is called after the plugin is installed. * Copies example config to project's config folder */ - protected function afterInstall():void + protected function afterInstall(): void { $configSourceFile = __DIR__ . DIRECTORY_SEPARATOR . 'config.example.php'; $configTargetFile = \Craft::$app->getConfig()->configDir . DIRECTORY_SEPARATOR . $this->handle . '.php'; From a89293584e4f5cd186421ff228e03ada386928f8 Mon Sep 17 00:00:00 2001 From: Linnea Date: Fri, 6 Jan 2023 16:18:17 -0500 Subject: [PATCH 6/8] Updating declarations for php 8.1 --- src/TwigExtension.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/TwigExtension.php b/src/TwigExtension.php index d27fb58..9d95413 100644 --- a/src/TwigExtension.php +++ b/src/TwigExtension.php @@ -11,7 +11,7 @@ class TwigExtension extends AbstractExtension implements GlobalsInterface * * @return array An array of global variables */ - public function getGlobals() + public function getGlobals(): array { return [ 'upper' => [ From c6063dace6f33a9b214d9012fbbbab879e848785 Mon Sep 17 00:00:00 2001 From: Linnea Date: Tue, 31 Jan 2023 10:56:02 -0500 Subject: [PATCH 7/8] PHP 8 updates --- src/jobs/PurgeCacheJob.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jobs/PurgeCacheJob.php b/src/jobs/PurgeCacheJob.php index 7210177..5853464 100644 --- a/src/jobs/PurgeCacheJob.php +++ b/src/jobs/PurgeCacheJob.php @@ -19,7 +19,7 @@ class PurgeCacheJob extends BaseJob /** * @inheritdoc */ - public function execute($queue) + public function execute($queue): bool { if (!$this->tag) { return false; From 1209c48a2b8a7e0c7df8e9c8eebf959af09a3988 Mon Sep 17 00:00:00 2001 From: Linnea Date: Tue, 31 Jan 2023 11:28:03 -0500 Subject: [PATCH 8/8] Fixing job execution declation --- src/jobs/PurgeCacheJob.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/jobs/PurgeCacheJob.php b/src/jobs/PurgeCacheJob.php index 5853464..8d0f4d3 100644 --- a/src/jobs/PurgeCacheJob.php +++ b/src/jobs/PurgeCacheJob.php @@ -19,10 +19,10 @@ class PurgeCacheJob extends BaseJob /** * @inheritdoc */ - public function execute($queue): bool + public function execute($queue): void { if (!$this->tag) { - return false; + return; } // Get registered purger