diff --git a/CHANGELOG.md b/CHANGELOG.md index 407c653..1c55506 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## [2.0.0] - 2023-XX-XX +- Prepare for Craft 4 compatibility +- ... + ## [1.9.2] - 2022-03-26 - Fix issues with Supertable / exclude SuperTableBlockElement diff --git a/composer.json b/composer.json index 913f2a1..4ff3c15 100644 --- a/composer.json +++ b/composer.json @@ -24,11 +24,13 @@ } ], "require": { - "craftcms/cms": "^3.2.0", + "craftcms/cms": "^4.1.0", "guzzlehttp/guzzle": "^6.5.5|^7.2.0" }, "require-dev": { - "vimeo/psalm": "^4.4" + "vimeo/psalm": "^4.4", + "craftcms/rector": "dev-main", + "craftcms/phpstan": "dev-main" }, "autoload": { "psr-4": { @@ -45,5 +47,14 @@ "hasCpSettings": false, "hasCpSection": false, "changelogUrl": "https://raw.githubusercontent.com/ostark/upper/master/CHANGELOG.md" + }, + "minimum-stability": "dev", + "prefer-stable": true, + "config": { + "allow-plugins": { + "yiisoft/yii2-composer": true, + "craftcms/plugin-installer": true, + "composer/package-versions-deprecated": true + } } } diff --git a/phpstan.neon b/phpstan.neon new file mode 100644 index 0000000..60da242 --- /dev/null +++ b/phpstan.neon @@ -0,0 +1,10 @@ +includes: + - vendor/craftcms/phpstan/phpstan.neon + +parameters: + level: 0 + paths: + - src + treatPhpDocTypesAsCertain: false + ignoreErrors: + - "#Unsafe usage of new static#" diff --git a/src/EventRegistrar.php b/src/EventRegistrar.php index 156e44c..255dd12 100644 --- a/src/EventRegistrar.php +++ b/src/EventRegistrar.php @@ -65,6 +65,7 @@ public static function registerFrontendEvents() $request->getIsActionRequest() || !$request->getIsGet() ) { + /** @var \ostark\upper\behaviors\CacheControlBehavior|\ostark\upper\behaviors\TagHeaderBehavior|Response $response */ $response = \Craft::$app->getResponse(); $response->addCacheControlDirective('private'); $response->addCacheControlDirective('no-cache'); @@ -93,7 +94,7 @@ public static function registerFrontendEvents() // Add the tags to the response header Event::on(View::class, View::EVENT_AFTER_RENDER_PAGE_TEMPLATE, function (TemplateEvent $event) { - /** @var \yii\web\Response $response */ + /** @var \yii\web\Response|\ostark\upper\behaviors\CacheControlBehavior|\ostark\upper\behaviors\TagHeaderBehavior $response */ $response = \Craft::$app->getResponse(); $plugin = Plugin::getInstance(); $tagCollection = $plugin->getTagCollection(); @@ -121,7 +122,7 @@ public static function registerFrontendEvents() // Flag truncation if (count($tags) > count($maxedTags)) { - $headers->set(Plugin::TRUNCATED_HEADER_NAME, count($tags) - count($maxedTags)); + $headers->set(Plugin::TRUNCATED_HEADER_NAME, (string) (count($tags) - count($maxedTags))); } $response->setSharedMaxAge($maxAge); diff --git a/src/Plugin.php b/src/Plugin.php index 255e0fa..73e4d5e 100644 --- a/src/Plugin.php +++ b/src/Plugin.php @@ -41,7 +41,7 @@ class Plugin extends BasePlugin 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'; /** @@ -108,11 +108,9 @@ public function getTagCollection(): TagCollection // ========================================================================= /** - * Creates and returns the model used to store the plugin’s settings. - * - * @return \craft\base\Model|null + * Creates and returns the model used to store the plugin’s settings */ - protected function createSettingsModel() + protected function createSettingsModel(): Settings { return new Settings(); } @@ -122,7 +120,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'; 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' => [ diff --git a/src/drivers/AbstractPurger.php b/src/drivers/AbstractPurger.php index 826b159..e0d5f7b 100644 --- a/src/drivers/AbstractPurger.php +++ b/src/drivers/AbstractPurger.php @@ -46,6 +46,20 @@ public function purgeUrlsByTag(string $tag) return false; } + + /** + * @param array $urls + * + * @return bool + */ + public function purgeUrls(array $urls) + { + $joinedUrls = implode(',', $urls); + \Craft::warning("Method purgeUrls([$joinedUrls]') was called - not implemented by driver ", "upper"); + + return true; + } + /** * Get cached urls by given tag * @@ -113,4 +127,7 @@ public function clearLocalCache() } + + + } diff --git a/src/drivers/Cloudflare.php b/src/drivers/Cloudflare.php index 6e5ab33..a8d9aee 100644 --- a/src/drivers/Cloudflare.php +++ b/src/drivers/Cloudflare.php @@ -101,7 +101,7 @@ public function purgeAll() * @return bool * @throws \ostark\upper\exceptions\CloudflareApiException */ - protected function sendRequest($method = 'DELETE', string $type, array $params = []) + protected function sendRequest($method = 'DELETE', string $type = 'purge_cache', array $params = []) { $client = $this->getClient(); diff --git a/src/drivers/Fastly.php b/src/drivers/Fastly.php index 90a64d5..5c18316 100644 --- a/src/drivers/Fastly.php +++ b/src/drivers/Fastly.php @@ -111,7 +111,7 @@ public function purgeAll() * @return bool * @throws \ostark\upper\exceptions\FastlyApiException */ - protected function sendRequest(string $method = 'PURGE', string $uri, array $headers = []) + protected function sendRequest(string $method = 'PURGE', string $uri = '', array $headers = []) { $client = new Client([ 'base_uri' => self::API_ENDPOINT, diff --git a/src/drivers/Keycdn.php b/src/drivers/Keycdn.php index 1ff8b45..b06ef55 100644 --- a/src/drivers/Keycdn.php +++ b/src/drivers/Keycdn.php @@ -72,7 +72,7 @@ public function purgeAll() * @return bool * @throws \ostark\upper\exceptions\KeycdnApiException */ - protected function sendRequest($method = 'DELETE', string $type, array $params = []) + protected function sendRequest($method = 'DELETE', string $type = 'purgetag', array $params = []) { $token = base64_encode("{$this->apiKey}:"); $client = new Client([ diff --git a/src/jobs/PurgeCacheJob.php b/src/jobs/PurgeCacheJob.php index 7210177..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) + public function execute($queue): void { if (!$this->tag) { - return false; + return; } // Get registered purger diff --git a/src/models/Settings.php b/src/models/Settings.php index 047ced7..8bf3d17 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'],