diff --git a/src/Seomatic.php b/src/Seomatic.php index 8af80a73a..82c9d2ac7 100644 --- a/src/Seomatic.php +++ b/src/Seomatic.php @@ -17,7 +17,6 @@ use craft\base\Model; use craft\base\Plugin; use craft\elements\Entry; -use craft\elements\User; use craft\errors\SiteNotFoundException; use craft\events\DefineGqlTypeFieldsEvent; use craft\events\ElementEvent; @@ -258,6 +257,7 @@ public function init(): void public function getSettings(): ?Model { // For all the emojis + /* @var Settings $settingsModel */ $settingsModel = parent::getSettings(); if ($settingsModel !== null && !self::$savingSettings) { $attributes = $settingsModel->attributes(); @@ -314,9 +314,12 @@ public function clearAllCaches(): void $gql->invalidateCaches(); } // If the FastCGI Cache Bust plugin is installed, clear its caches too + /** @var ?FastcgiCacheBust $plugin */ $plugin = Craft::$app->getPlugins()->getPlugin('fastcgi-cache-bust'); if ($plugin !== null) { - FastcgiCacheBust::$plugin->cache->clearAll(); + // FastcgiCacheBust has an error in its PHPdoc + /** @phpstan-ignore-next-line */ + $plugin->cache->clearAll(); } } @@ -339,7 +342,6 @@ public function getCpNavItem(): ?array { $subNavs = []; $navItem = parent::getCpNavItem(); - /** @var User $currentUser */ $request = Craft::$app->getRequest(); $siteSuffix = ''; if ($request->getSegment(1) === 'seomatic') { @@ -526,7 +528,7 @@ static function(ModelEvent $event) { 'Element::EVENT_AFTER_PROPAGATE', __METHOD__ ); - /** @var $element Element */ + /** @var Element $element */ $element = $event->sender; self::$plugin->metaBundles->invalidateMetaBundleByElement( $element, @@ -546,7 +548,7 @@ static function(ElementEvent $event) { 'Elements::EVENT_AFTER_DELETE_ELEMENT', __METHOD__ ); - /** @var $element Element */ + /** @var Element $element */ $element = $event->element; self::$plugin->metaBundles->invalidateMetaBundleByElement( $element, diff --git a/src/autocompletes/TrackingVarsAutocomplete.php b/src/autocompletes/TrackingVarsAutocomplete.php index ae09c09c8..849e4f27e 100644 --- a/src/autocompletes/TrackingVarsAutocomplete.php +++ b/src/autocompletes/TrackingVarsAutocomplete.php @@ -41,7 +41,7 @@ class TrackingVarsAutocomplete extends Autocomplete public $type = AutocompleteTypes::TwigExpressionAutocomplete; /** - * @var string Whether the autocomplete should be parsed with . -delimited nested sub-properties + * @var bool Whether the autocomplete should be parsed with . -delimited nested sub-properties */ public $hasSubProperties = false; diff --git a/src/base/Container.php b/src/base/Container.php index 7c94ea697..c662c46e7 100644 --- a/src/base/Container.php +++ b/src/base/Container.php @@ -35,12 +35,11 @@ abstract class Container extends FluentModel implements ContainerInterface * * @param array $config * - * @return null|Container + * @return static */ public static function create(array $config = []) { $className = static::class; - /** @var Container $model */ $model = new $className($config); $model->normalizeContainerData(); diff --git a/src/base/FluentModel.php b/src/base/FluentModel.php index a90c099c0..0fa020e6a 100644 --- a/src/base/FluentModel.php +++ b/src/base/FluentModel.php @@ -11,12 +11,11 @@ namespace nystudio107\seomatic\base; -use Craft; use craft\base\Model; - -use twig\Markup; - +use ReflectionClass; +use Twig\Markup; use yii\base\InvalidArgumentException; +use function is_object; /** * @author nystudio107 @@ -32,7 +31,7 @@ abstract class FluentModel extends Model * Remove any properties that don't exist in the model * * @param string $class - * @param array $config + * @param array $config */ protected static function cleanProperties(string $class, array &$config) { @@ -50,22 +49,13 @@ protected static function cleanProperties(string $class, array &$config) * Add fluent getters/setters for this class * * @param string $method The method name (property name) - * @param array $args The arguments list + * @param array $args The arguments list * * @return mixed The value of the property */ public function __call($method, $args) { - try { - $reflector = new \ReflectionClass(static::class); - } catch (\ReflectionException $e) { - Craft::error( - $e->getMessage(), - __METHOD__ - ); - - return null; - } + $reflector = new ReflectionClass(static::class); if (!$reflector->hasProperty($method)) { throw new InvalidArgumentException("Property {$method} doesn't exist"); } @@ -76,7 +66,7 @@ public function __call($method, $args) } // Set the property $value = $args[0]; - if (\is_object($value) && $value instanceof Markup) { + if (is_object($value) && $value instanceof Markup) { $value = (string)$value; } $property->setValue($this, $value); diff --git a/src/base/MetaContainer.php b/src/base/MetaContainer.php index 7e7a849f0..9988236a6 100644 --- a/src/base/MetaContainer.php +++ b/src/base/MetaContainer.php @@ -67,7 +67,6 @@ public function renderArray(array $params = []): array $htmlArray = []; if ($this->prepForInclusion()) { - /** @var $metaItemModel MetaItem */ foreach ($this->data as $metaItemModel) { if ($metaItemModel->include) { $htmlArray[$metaItemModel->key] = $metaItemModel->renderAttributes($params); diff --git a/src/base/MetaItem.php b/src/base/MetaItem.php index d9ad74dcd..aff896083 100644 --- a/src/base/MetaItem.php +++ b/src/base/MetaItem.php @@ -12,12 +12,17 @@ namespace nystudio107\seomatic\base; use Craft; +use Exception; use nystudio107\seomatic\behaviors\MetaItemAttributeParserBehavior; use nystudio107\seomatic\helpers\ArrayHelper; use nystudio107\seomatic\helpers\Dependency; use nystudio107\seomatic\models\MetaJsonLd; use nystudio107\seomatic\Seomatic; use yii\helpers\Inflector; +use function count; +use function get_class; +use function is_array; +use function is_string; /** * @author nystudio107 @@ -52,9 +57,9 @@ public function init(): void $envVars = null; try { $envVars = ArrayHelper::getValue($this->environment, Seomatic::$environment); - } catch (\Exception $e) { + } catch (Exception $e) { } - if (\is_array($envVars)) { + if (is_array($envVars)) { foreach ($envVars as $key => $value) { $attributes[$key] = $value; } @@ -155,7 +160,7 @@ public function debugMetaItem( $extraInfo = ''; // Add a URL to the schema.org type if this is a MetaJsonLD object if ($isMetaJsonLdModel) { - /** @var $this MetaJsonLd */ + /** @var MetaJsonLd $this */ $extraInfo = ' for http://schema.org/' . $this->type; } $errorMsg = @@ -187,11 +192,10 @@ public function debugMetaItem( // Extra debugging info for MetaJsonLd objects if ($isMetaJsonLdModel) { /** @var MetaJsonLd $className */ - $className = \get_class($this); - if (!empty($className::$schemaPropertyDescriptions[$param])) { + $className = get_class($this); + if (!empty($className->schemaPropertyDescriptions[$param])) { $errorMsg = Craft::t('seomatic', $errorLabel) . $param; - /** @var $className MetaJsonLd */ - $errorMsg .= ' -> ' . $className::$schemaPropertyDescriptions[$param]; + $errorMsg .= ' -> ' . $className->schemaPropertyDescriptions[$param]; Craft::info($errorMsg, __METHOD__); } } @@ -207,7 +211,7 @@ public function debugMetaItem( */ public function tagAttributes(): array { - $attrs = $this->tagAttrs ?? []; + $attrs = $this->tagAttrs; if (!is_array($attrs)) { $attrs = []; } @@ -243,16 +247,16 @@ public function tagAttributesArray(): array // See if any of the potentially array properties actually are foreach (static::ARRAY_PROPERTIES as $arrayProperty) { - if (!empty($options[$arrayProperty]) && \is_array($options[$arrayProperty])) { - $optionsCount = \count($options[$arrayProperty]) > $optionsCount - ? \count($options[$arrayProperty]) : $optionsCount; + if (!empty($options[$arrayProperty]) && is_array($options[$arrayProperty])) { + $optionsCount = count($options[$arrayProperty]) > $optionsCount + ? count($options[$arrayProperty]) : $optionsCount; } } // Return an array of resulting options while ($optionsCount--) { $resultOptions = $options; foreach ($resultOptions as $key => $value) { - $resultOptions[$key] = (\is_array($value) && isset($value[$optionsCount])) + $resultOptions[$key] = (is_array($value) && isset($value[$optionsCount])) ? $value[$optionsCount] : $value; } $result[] = $resultOptions; @@ -272,10 +276,10 @@ public function validateStringOrArray( $params, ) { $validated = false; - if (\is_string($attribute)) { + if (is_string($attribute)) { $validated = true; } - if (\is_array($attribute)) { + if (is_array($attribute)) { $validated = true; } if (!$validated) { diff --git a/src/base/MetaService.php b/src/base/MetaService.php index d97160275..9d75be16f 100644 --- a/src/base/MetaService.php +++ b/src/base/MetaService.php @@ -13,8 +13,6 @@ use craft\base\Component; -use nystudio107\seomatic\Seomatic; - /** * @author nystudio107 * @package Seomatic @@ -35,6 +33,7 @@ abstract class MetaService extends Component implements MetaServiceInterface */ public function get(string $key, string $handle = '') { + return null; } /** @@ -42,6 +41,9 @@ public function get(string $key, string $handle = '') */ public function create(array $config = [], $add = true) { + // The non-abstract classes always return a MetaItem + /** @phpstan-ignore-next-line */ + return null; } /** @@ -49,6 +51,7 @@ public function create(array $config = [], $add = true) */ public function add($metaItem, string $handle = '') { + return null; } /** @@ -56,6 +59,7 @@ public function add($metaItem, string $handle = '') */ public function render() { + return null; } /** @@ -63,5 +67,6 @@ public function render() */ public function container(string $handle = '') { + return null; } } diff --git a/src/controllers/ContentSeoController.php b/src/controllers/ContentSeoController.php index bfe6dc8e3..987d441ec 100644 --- a/src/controllers/ContentSeoController.php +++ b/src/controllers/ContentSeoController.php @@ -17,6 +17,7 @@ use nystudio107\seomatic\Seomatic; use yii\web\BadRequestHttpException; use yii\web\Response; +use function count; /** * @author nystudio107 @@ -42,7 +43,7 @@ class ContentSeoController extends Controller // ========================================================================= /** - * @var bool|array + * @inheritdoc */ protected array|bool|int $allowAnonymous = [ ]; @@ -152,8 +153,8 @@ public function actionMetaBundles( $dataItem['robots'] = $metaBundle->metaGlobalVars->robots; // Calculate the setup stat $stat = 0; - $numGrades = \count(SettingsController::SETUP_GRADES); - $numFields = \count(SettingsController::SEO_SETUP_FIELDS); + $numGrades = count(SettingsController::SETUP_GRADES); + $numFields = count(SettingsController::SEO_SETUP_FIELDS); foreach (SettingsController::SEO_SETUP_FIELDS as $setupField => $setupLabel) { $stat += (int)!empty($metaBundle->metaGlobalVars[$setupField]); $value = $variables['contentSetupChecklist'][$setupField]['value'] ?? 0; diff --git a/src/controllers/SettingsController.php b/src/controllers/SettingsController.php index 79f6d39e6..0c4a969d6 100644 --- a/src/controllers/SettingsController.php +++ b/src/controllers/SettingsController.php @@ -13,8 +13,8 @@ use craft\elements\Asset; use craft\errors\MissingComponentException; use craft\helpers\UrlHelper; -use craft\models\Site; use craft\web\Controller; +use craft\web\UrlManager; use DateTime; use nystudio107\seomatic\assetbundles\seomatic\SeomaticAsset; use nystudio107\seomatic\autocompletes\TrackingVarsAutocomplete; @@ -221,7 +221,7 @@ public function actionDashboard(string $siteHandle = null, bool $showWelcome = f * * @param string $subSection * @param string|null $siteHandle - * @param null $loadFromSiteHandle + * @param string|null $loadFromSiteHandle * * @return Response The rendered result * @throws NotFoundHttpException @@ -341,7 +341,7 @@ public function actionGlobal(string $subSection = 'general', string $siteHandle } /** - * @return Response + * @return Response|null * @throws BadRequestHttpException * @throws MissingComponentException */ @@ -412,7 +412,9 @@ public function actionSaveGlobal() Craft::error(print_r($metaBundle->metaGlobalVars->getErrors(), true), __METHOD__); Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save settings due to a Twig error.")); // Send the redirect back to the template - Craft::$app->getUrlManager()->setRouteParams([ + /** @var UrlManager $urlManager */ + $urlManager = Craft::$app->getUrlManager(); + $urlManager->setRouteParams([ 'editedMetaBundle' => $metaBundle, ]); @@ -490,8 +492,8 @@ public function actionContent(string $siteHandle = null): Response * @param string $sourceBundleType * @param string $sourceHandle * @param string|null $siteHandle - * @param int|null $typeId - * @param null $loadFromSiteHandle + * @param string|int|null $typeId + * @param string|null $loadFromSiteHandle * * @return Response The rendered result * @throws NotFoundHttpException @@ -504,8 +506,7 @@ public function actionEditContent( string $siteHandle = null, $typeId = null, $loadFromSiteHandle = null, - ): Response - { + ): Response { $variables = []; // @TODO: Let people choose an entry/categorygroup/product as the preview // Get the site to edit @@ -683,8 +684,8 @@ public function actionSaveContent(): Response * Site settings * * @param string $subSection - * @param string $siteHandle - * @param null $loadFromSiteHandle + * @param string|null $siteHandle + * @param string|null $loadFromSiteHandle * * @return Response The rendered result * @throws NotFoundHttpException @@ -880,8 +881,8 @@ public function actionPlugin(): Response * Tracking settings * * @param string $subSection - * @param string $siteHandle - * @param null $loadFromSiteHandle + * @param string|null $siteHandle + * @param string|null $loadFromSiteHandle * * @return Response The rendered result * @throws NotFoundHttpException @@ -964,7 +965,7 @@ public function actionTracking(string $subSection = 'gtag', string $siteHandle = } /** - * @return Response + * @return Response|null * @throws BadRequestHttpException * @throws MissingComponentException */ @@ -986,7 +987,7 @@ public function actionSaveTracking() foreach ($metaBundle->metaContainers as $metaContainer) { if ($metaContainer::CONTAINER_TYPE === MetaScriptContainer::CONTAINER_TYPE) { $data = $metaContainer->getData($scriptHandle); - /** @var MetaScript $data */ + /** @var MetaScript|null $data */ if ($data) { /** @var array $scriptData */ foreach ($scriptData as $key => $value) { @@ -1008,7 +1009,9 @@ public function actionSaveTracking() if ($hasErrors) { Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save tracking settings due to a Twig error.")); // Send the redirect back to the template - Craft::$app->getUrlManager()->setRouteParams([ + /** @var UrlManager $urlManager */ + $urlManager = Craft::$app->getUrlManager(); + $urlManager->setRouteParams([ 'editedMetaBundle' => $metaBundle, ]); @@ -1056,8 +1059,10 @@ public function actionSavePluginSettings() if (!Craft::$app->getPlugins()->savePluginSettings($plugin, $settings)) { Craft::$app->getSession()->setError(Craft::t('app', "Couldn't save plugin settings.")); - // Send the plugin back to the template - Craft::$app->getUrlManager()->setRouteParams([ + // Send the redirect back to the template + /** @var UrlManager $urlManager */ + $urlManager = Craft::$app->getUrlManager(); + $urlManager->setRouteParams([ 'plugin' => $plugin, ]); @@ -1076,7 +1081,7 @@ public function actionSavePluginSettings() /** * Return a siteId from a siteHandle * - * @param string $siteHandle + * @param string|null $siteHandle * * @return int|null * @throws NotFoundHttpException @@ -1098,10 +1103,11 @@ protected function getSiteIdFromHandle($siteHandle) } /** - * @param string $siteHandle - * @param $siteId - * @param $variables - * + * @param $siteHandle + * @param $siteId + * @param array $variables + * @param $element + * @return void * @throws ForbiddenHttpException */ protected function setMultiSiteVariables($siteHandle, &$siteId, array &$variables, $element = null) @@ -1113,7 +1119,6 @@ protected function setMultiSiteVariables($siteHandle, &$siteId, array &$variable $variables['enabledSiteIds'] = []; $variables['siteIds'] = []; - /** @var Site $site */ foreach ($sites->getEditableSiteIds() as $editableSiteId) { $variables['enabledSiteIds'][] = $editableSiteId; $variables['siteIds'][] = $editableSiteId; @@ -1207,8 +1212,7 @@ protected function setContentFieldSourceVariables( string $sourceHandle, string $groupName, array &$variables, - ) - { + ) { $variables['textFieldSources'] = array_merge( ['entryGroup' => ['optgroup' => $groupName . ' Fields'], 'title' => 'Title'], FieldHelper::fieldsOfTypeFromSource( diff --git a/src/debug/views/seomatic/detail.php b/src/debug/views/seomatic/detail.php index d2fd96fbe..616591c90 100644 --- a/src/debug/views/seomatic/detail.php +++ b/src/debug/views/seomatic/detail.php @@ -1,10 +1,13 @@ -
Expand Sub-Properties
- - - - - - - - $subValue): ?> - - + + - + ]) ?> + + +
PropertyValue
+
+ Expand Sub-Properties +
+ + - + + + + + $subValue): ?> + + + + + render('render-value', [ 'value' => $subValue ?? '', 'meta' => $meta, - ]) ?> - render('render-value', [ - 'value' => $subValue ?? '', - 'meta' => $meta, - ]) ?> - -
render('render-copy-menu', [ + PropertyValue
render('render-copy-menu', [ + 'value' => $subValue ?? '', + 'meta' => $meta, + ]) ?>
$errorCat): ?>
    $errors): ?>
not included
$errorCat): ?> +
+
+ + + +
not included
+ diff --git a/src/debug/views/seomatic/render-value.php b/src/debug/views/seomatic/render-value.php index 264ab67b1..2bb82781c 100644 --- a/src/debug/views/seomatic/render-value.php +++ b/src/debug/views/seomatic/render-value.php @@ -1,35 +1,51 @@ -
Expand Sub-Properties
- - - - - - - - - $subValue): ?> - - + + - + ]) ?> + + +
PropertyValue
+
+ Expand Sub-Properties +
+ + - - render('render-value', [ + + + + + + + $subValue): ?> + + + + + render('render-value', [ 'value' => $subValue ?? '', 'meta' => $meta, - ]) ?> - -
render('render-copy-menu', [ - 'value' => $subValue ?? '', - 'meta' => $meta, - ]) ?>PropertyValue
render('render-copy-menu', [ + 'value' => $subValue ?? '', + 'meta' => $meta, + ]) ?>
charset, true) ?>
+
+
+ + + charset, true) ?> diff --git a/src/debug/views/seomatic/rendered-tags.php b/src/debug/views/seomatic/rendered-tags.php index 525c0c38e..991c45a55 100644 --- a/src/debug/views/seomatic/rendered-tags.php +++ b/src/debug/views/seomatic/rendered-tags.php @@ -1,10 +1,15 @@
Rendered Tags diff --git a/src/debug/views/seomatic/summary.php b/src/debug/views/seomatic/summary.php index 567a94854..9a6da961a 100644 --- a/src/debug/views/seomatic/summary.php +++ b/src/debug/views/seomatic/summary.php @@ -1,9 +1,12 @@