Skip to content

Commit

Permalink
refactor: phpstan code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
khalwat committed Oct 14, 2024
1 parent 23b96cd commit a0d9673
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 24 deletions.
5 changes: 1 addition & 4 deletions src/RouteMap.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
use craft\services\Elements;
use craft\utilities\ClearCaches;
use craft\web\twig\variables\CraftVariable;
use nystudio107\routemap\services\Routes as RoutesService;
use nystudio107\routemap\services\ServicesTrait;
use nystudio107\routemap\variables\RouteMapVariable;
use yii\base\Event;
Expand All @@ -30,8 +29,6 @@
* @author nystudio107
* @package RouteMap
* @since 1.0.0
*
* @property RoutesService routes
*/
class RouteMap extends Plugin
{
Expand Down Expand Up @@ -68,7 +65,7 @@ class RouteMap extends Plugin

// Public Methods
// =========================================================================

/**
* @inheritdoc
*/
Expand Down
5 changes: 0 additions & 5 deletions src/controllers/RoutesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,6 @@ class RoutesController extends Controller
// Protected Properties
// =========================================================================

/**
* @var bool|array Allows anonymous access to this controller's actions.
* The actions must be in 'kebab-case'
* @access protected
*/
protected array|bool|int $allowAnonymous = [
'get-all-urls',
'get-section-urls',
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static function fieldsOfType(ElementInterface $element, string $fieldType
}

$fields = $layout->getCustomFields();
/** @var $field BaseField */
/** @var BaseField $field */
foreach ($fields as $field) {
if ($field instanceof $fieldType) {
$foundFields[] = $field->handle;
Expand Down Expand Up @@ -72,7 +72,7 @@ public static function matrixFieldsOfType(MatrixBlock $matrixBlock, string $fiel

if ($matrixBlockTypeModel !== null) {
$fields = $matrixBlockTypeModel->getCustomFields();
/** @var $field BaseField */
/** @var BaseField $field */
foreach ($fields as $field) {
if ($field instanceof $fieldType) {
$foundFields[] = $field->handle;
Expand Down
20 changes: 10 additions & 10 deletions src/services/Routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ public function getSectionRouteRules(string $section, string $format = 'Craft',
]);

// Just return the data if it's already cached
return $cache->getOrSet($cacheKey, function () use ($section, $format, $siteId): array {
return $cache->getOrSet($cacheKey, function() use ($section, $format, $siteId): array {
Craft::info(
'Route Map cache miss: ' . $section,
__METHOD__
Expand Down Expand Up @@ -248,7 +248,6 @@ public function getSectionRouteRules(string $section, string $format = 'Craft',
*/
public function getCategoryUrls(string $category, array $criteria = [], ?int $siteId = null): array
{

$criteria = array_merge([
'group' => $category,
], $criteria);
Expand Down Expand Up @@ -315,13 +314,13 @@ public function getCategoryRouteRules(int|string $category, string $format = 'Cr
],
]);
// Just return the data if it's already cached
return $cache->getOrSet($cacheKey, function () use ($category, $handle, $format, $siteId): array {
return $cache->getOrSet($cacheKey, function() use ($category, $handle, $format, $siteId): array {
Craft::info(
'Route Map cache miss: ' . $category,
__METHOD__
);
$resultingRoutes = [];
$category = is_object($category) ? $category : Craft::$app->getCategories()->getGroupByHandle($handle);
$category = Craft::$app->getCategories()->getGroupByHandle($handle);
if ($category) {
$sites = $category->getSiteSettings();

Expand Down Expand Up @@ -377,15 +376,15 @@ public function getUrlAssetUrls(string $url, array $assetTypes = ['image'], ?int
]);

// Just return the data if it's already cached
return $cache->getOrSet($cacheKey, function () use ($uri, $assetTypes, $siteId): array {
return $cache->getOrSet($cacheKey, function() use ($uri, $assetTypes, $siteId): array {
Craft::info(
'Route Map cache miss: ' . $uri,
__METHOD__
);
$resultingAssetUrls = [];

// Find the element that matches this URI
/** @var $element Entry */
/** @var ?Entry $element */
$element = Craft::$app->getElements()->getElementByUri($uri, $siteId, true);
if ($element) {
// Iterate any Assets fields for this entry
Expand Down Expand Up @@ -447,7 +446,7 @@ public function getElementUrls(string|ElementInterface $elementType, array $crit
], $criteria);
// Set up our cache criteria
/* @var ElementInterface $elementInterface */
$elementInterface = is_object($elementType) ? $elementType : new $elementType;
$elementInterface = is_object($elementType) ? $elementType : new $elementType();
$cacheKey = $this->getCacheKey($this::ROUTEMAP_ELEMENT_URLS, [$elementInterface, $criteria, $siteId]);
$duration = $devMode ? $this::DEVMODE_ROUTEMAP_CACHE_DURATION : $this::ROUTEMAP_CACHE_DURATION;
$dependency = new TagDependency([
Expand All @@ -457,7 +456,7 @@ public function getElementUrls(string|ElementInterface $elementType, array $crit
]);

// Just return the data if it's already cached
return $cache->getOrSet($cacheKey, function () use ($elementInterface, $criteria): array {
return $cache->getOrSet($cacheKey, function() use ($elementInterface, $criteria): array {
Craft::info(
'Route Map cache miss: ' . $elementInterface::class,
__METHOD__
Expand Down Expand Up @@ -500,8 +499,9 @@ public function invalidateCache(): void
* Get all routes rules defined in the config/routes.php file and CMS
*
* @return array
* @var ?int $siteId
* @var bool $includeGlobal - merge global routes with the site rules
* @property ?int $siteId
*
* @property bool $includeGlobal - merge global routes with the site rules
*/
public function getRouteRules(?int $siteId = null, bool $includeGlobal = true): array
{
Expand Down
2 changes: 1 addition & 1 deletion src/services/ServicesTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
* @package routemap
* @since 4.0.1
*
* @property RoutesService $helper
* @property RoutesService $routes
*/
trait ServicesTrait
{
Expand Down
4 changes: 2 additions & 2 deletions src/translations/en/route-map.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@
* @since 1.0.0
*/
return [
'Route Map Cache' => 'Route Map Cache',
'{name} plugin loaded' => '{name} plugin loaded'
'Route Map Cache' => 'Route Map Cache',
'{name} plugin loaded' => '{name} plugin loaded',
];

0 comments on commit a0d9673

Please sign in to comment.