Skip to content

Commit

Permalink
Revert "PHPstan level 2"
Browse files Browse the repository at this point in the history
This reverts commit fc1fecf.
  • Loading branch information
janhenckens committed Oct 11, 2023
1 parent e572647 commit 2d2dd81
Show file tree
Hide file tree
Showing 10 changed files with 30 additions and 48 deletions.
7 changes: 5 additions & 2 deletions src/SeoFields.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
namespace studioespresso\seofields;

use Craft;
use craft\base\Model;
use craft\base\Plugin;
use craft\events\ElementEvent;
use craft\events\EntryTypeEvent;
Expand Down Expand Up @@ -159,7 +158,11 @@ public function getCpNavItem(): ?array
return $navItem;
}

protected function createSettingsModel(): ? Model
// Protected Methods
// =========================================================================
// Protected Methods
// =========================================================================
protected function createSettingsModel(): ?craft\base\Model
{
return new Settings();
}
Expand Down
7 changes: 1 addition & 6 deletions src/controllers/CpApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class CpApiController extends Controller
public const REDIRECT_BASE = "seo-fields/cp-api/redirect";

/**
* @param null $siteHandle
* @return \yii\web\Response
*/
public function actionNotFound()
Expand Down Expand Up @@ -57,9 +58,6 @@ public function actionNotFound()

$formatter = Craft::$app->getFormatter();
foreach ($query->all() as $row) {
/**
* @var NotFoundRecord|null $row
*/
$lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
$row = [
'id' => $row->id,
Expand Down Expand Up @@ -138,9 +136,6 @@ public function actionRedirects()
];

foreach ($query->all() as $row) {
/**
* @var RedirectRecord|null $row
*/
$lastHit = DateTimeHelper::toDateTime($row->dateLastHit);
$row = [
'url' => UrlHelper::cpUrl("seo-fields/redirects/edit/{$row->id}"),
Expand Down
10 changes: 10 additions & 0 deletions src/controllers/RedirectsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ private function getSitesMenu()

private function getHeaders($reader)
{
// Support for league/csv v8 with a header
try {
return $reader->fetchOne(0);
} catch (\Throwable $e) {
}

try {
$reader->setHeaderOffset(0);
return $reader->getHeader();
Expand All @@ -183,6 +189,10 @@ private function getHeaders($reader)
}
private function getRows(Reader $reader)
{
try {
return $reader->fetchAll();
} catch (\Throwable $e) {
}

try {
return $reader->getIterator();
Expand Down
8 changes: 4 additions & 4 deletions src/migrations/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ protected function addForeignKeys()
{
// $name, $table, $columns, $refTable, $refColumns, $delete = null, $update = null)
$this->addForeignKey(
$this->db->getForeignKeyName(),
$this->db->getForeignKeyName(DefaultsRecord::tableName(), 'siteId'),
DefaultsRecord::tableName(),
'siteId',
'{{%sites}}',
Expand All @@ -131,7 +131,7 @@ protected function addForeignKeys()
);

$this->addForeignKey(
$this->db->getForeignKeyName(),
$this->db->getForeignKeyName(RedirectRecord::tableName(), 'siteId'),
RedirectRecord::tableName(),
'siteId',
'{{%sites}}',
Expand All @@ -140,7 +140,7 @@ protected function addForeignKeys()
);

$this->addForeignKey(
$this->db->getForeignKeyName(),
$this->db->getForeignKeyName(NotFoundRecord::tableName(), 'siteId'),
NotFoundRecord::tableName(),
'siteId',
'{{%sites}}',
Expand All @@ -149,7 +149,7 @@ protected function addForeignKeys()
);

$this->addForeignKey(
$this->db->getForeignKeyName(),
$this->db->getForeignKeyName(NotFoundRecord::tableName(), 'redirect'),
NotFoundRecord::tableName(),
'redirect',
'{{%seofields_redirects}}',
Expand Down
2 changes: 1 addition & 1 deletion src/migrations/m191114_182559_addNotFoundTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function safeUp()

if ($tablesCreated) {
$this->addForeignKey(
$this->db->getForeignKeyName(),
$this->db->getForeignKeyName(NotFoundRecord::tableName(), 'siteId'),
NotFoundRecord::tableName(),
'siteId',
'{{%sites}}',
Expand Down
4 changes: 2 additions & 2 deletions src/migrations/m191114_201532_addRedirectsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ public function safeUp()

if ($tablesCreated) {
$this->addForeignKey(
$this->db->getForeignKeyName(),
$this->db->getForeignKeyName(RedirectRecord::tableName(), 'siteId'),
RedirectRecord::tableName(),
'siteId',
'{{%sites}}',
'id',
'CASCADE'
);
$this->addForeignKey(
$this->db->getForeignKeyName(),
$this->db->getForeignKeyName(NotFoundRecord::tableName(), 'redirect'),
NotFoundRecord::tableName(),
'redirect',
'{{%seofields_redirects}}',
Expand Down
9 changes: 0 additions & 9 deletions src/records/NotFoundRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,6 @@
*/
class NotFoundRecord extends ActiveRecord
{

public $id;
public $dateLastHit;
public $urlPath;
public $matchType;
public $siteId;
public $counter;
public $handled;

// Public Static Methods
// =========================================================================
public static function tableName()
Expand Down
10 changes: 0 additions & 10 deletions src/records/RedirectRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,6 @@
*/
class RedirectRecord extends ActiveRecord
{

public $id;
public $dateLastHit;
public $counter;
public $matchType;
public $method;
public $siteId;
public $redirect;
public $pattern;

// Public Static Methods
// =========================================================================
public static function tableName()
Expand Down
7 changes: 4 additions & 3 deletions src/services/NotFoundService.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public function markAsHandled(NotFoundRecord|int $record): void
return;
}

/**
* @param NotFoundModel $model
* @return RedirectModel|false
*/
private function getMatchingRedirect(NotFoundModel $model): RedirectRecord|array|bool
{
Craft::debug("Check if our 404 is matched to a redirect", SeoFields::class);
Expand Down Expand Up @@ -193,9 +197,6 @@ private function shouldWeCleanupRedirects()
$toDelete->limit($limit);
$toDelete->orderBy("dateCreated ASC");
foreach ($toDelete->all() as $record) {
/**
* @var NotFoundRecord|null $record
*/
$this->deletetById($record->id);
}
}
Expand Down
14 changes: 3 additions & 11 deletions src/services/SitemapService.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use craft\helpers\Json;
use craft\helpers\UrlHelper;
use craft\models\Site;
use PhpCsFixer\DocBlock\Tag;
use studioespresso\seofields\SeoFields;
use yii\caching\TagDependency;

Expand Down Expand Up @@ -167,21 +166,14 @@ public function clearCaches($tags = [self::SITEMAP_CACHE_KEY])
);
}

/**
* @param Element|Entry|Category $element
* @return false|void
*/
public function clearCacheForElement(Element|Entry|Category $element)
public function clearCacheForElement(Element $element)
{
$elementType = get_class($element);
$typeHandle = explode('\\', $elementType);
$typeHandle = end($typeHandle);
switch (strtolower($typeHandle)) {
case 'entry':
/**
* @var Entry|null $element
*/
$section = Craft::$app->getSections()->getSectionById($element->sectionId);
$section = Craft::$app->getSections()->getSectionById($element->sectionId);
$id = $section->id;
break;
default:
Expand Down Expand Up @@ -215,6 +207,7 @@ private function _addElementsToSitemap($entries, $settings)
if ($seoField->columnSuffix) {
$field = $field . "_{$seoField->columnSuffix}";
}
/** @var $entry Element */
foreach ($entries as $entry) {
$siteEntries =
(new Query())->select(['elements_sites.siteId', 'uri', 'language'])
Expand Down Expand Up @@ -360,7 +353,6 @@ private function _shouldRenderProducts($sitemapSettings)
/** @phpstan-ignore-next-line */
$productTypeService = new ProductTypes();
$site = Craft::$app->getSites()->getCurrentSite();
/** @phpstan-ignore-next-line */
foreach ($productTypeService->getProductTypeSites($productType) as $productTypeSite) {
if ($productTypeSite->siteId == $site->id && $productTypeSite->hasUrls) {
return true;
Expand Down

0 comments on commit 2d2dd81

Please sign in to comment.