Skip to content

Commit

Permalink
Apply rector to php 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Fred Condo committed Aug 21, 2024
1 parent 0681d0f commit 69834f7
Show file tree
Hide file tree
Showing 12 changed files with 50 additions and 59 deletions.
6 changes: 3 additions & 3 deletions src/Analysis/FocusKeywordContentAnalysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
class FocusKeywordContentAnalysis extends Analysis
{
const FOCUS_KEYWORD_NOT_FOUND = 0;
const FOCUS_KEYWORD_SUCCESS = 1;
const FOCUS_KEYWORD_UNSET = -1;
public const FOCUS_KEYWORD_NOT_FOUND = 0;
public const FOCUS_KEYWORD_SUCCESS = 1;
public const FOCUS_KEYWORD_UNSET = -1;

private static $hidden_levels = [
'default'
Expand Down
6 changes: 3 additions & 3 deletions src/Analysis/FocusKeywordUniqueAnalysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
*/
class FocusKeywordUniqueAnalysis extends Analysis
{
const FOCUS_KEYWORD_INUSE = 0;
const FOCUS_KEYWORD_SUCCESS = 1;
const FOCUS_KEYWORD_UNSET = -1;
public const FOCUS_KEYWORD_INUSE = 0;
public const FOCUS_KEYWORD_SUCCESS = 1;
public const FOCUS_KEYWORD_UNSET = -1;

/**
* @return string
Expand Down
16 changes: 8 additions & 8 deletions src/Analysis/FocusKeywordUrlAnalysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
*/
class FocusKeywordUrlAnalysis extends Analysis
{
const FOCUS_KEYWORD_IRRELEVANT = -2;
const FOCUS_KEYWORD_NOT_IN_URL = 0;
const FOCUS_KEYWORD_SUCCESS = 1;
const FOCUS_KEYWORD_UNSET = -1;
public const FOCUS_KEYWORD_IRRELEVANT = -2;
public const FOCUS_KEYWORD_NOT_IN_URL = 0;
public const FOCUS_KEYWORD_SUCCESS = 1;
public const FOCUS_KEYWORD_UNSET = -1;

private static $hidden_levels = [
'default'
Expand All @@ -38,19 +38,19 @@ public function responses()
{
return [
static::FOCUS_KEYWORD_IRRELEVANT => [
_t( __CLASS__ . '.FOCUS_KEYWORD_IRRELEVANT', 'The focus keyword is irrelevant on the home page; this message will not display'),
_t( self::class . '.FOCUS_KEYWORD_IRRELEVANT', 'The focus keyword is irrelevant on the home page; this message will not display'),
'default'
],
static::FOCUS_KEYWORD_UNSET => [
_t( __CLASS__ . '.FOCUS_KEYWORD_UNSET', 'The focus keyword has not been set; consider setting this to improve content analysis'),
_t( self::class . '.FOCUS_KEYWORD_UNSET', 'The focus keyword has not been set; consider setting this to improve content analysis'),
'default'
],
static::FOCUS_KEYWORD_NOT_IN_URL => [
_t( __CLASS__ . '.FOCUS_KEYWORD_NOT_IN_URL', 'The focus keyword is not in the url segment; consider changing this and if you do SilverStripe will automatically redirect your old URL!'),
_t( self::class . '.FOCUS_KEYWORD_NOT_IN_URL', 'The focus keyword is not in the url segment; consider changing this and if you do SilverStripe will automatically redirect your old URL!'),
'warning'
],
static::FOCUS_KEYWORD_SUCCESS => [
_t( __CLASS__ . '.FOCUS_KEYWORD_SUCCESS', 'The focus keyword is in the url segment; this is great!'),
_t( self::class . '.FOCUS_KEYWORD_SUCCESS', 'The focus keyword is in the url segment; this is great!'),
'success'
],
];
Expand Down
14 changes: 7 additions & 7 deletions src/Analysis/TitleAnalysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
*/
class TitleAnalysis extends Analysis
{
const TITLE_FOCUS_KEYWORD_POSITION = 4;
const TITLE_IS_HOME = -1;
const TITLE_NO_FOCUS_KEYWORD = 3; // only checked if the focus keyword has been defined
const TITLE_OK_BUT_SHORT = 1;
const TITLE_SUCCESS = 5;
const TITLE_TOO_LONG = 2;
const TITLE_TOO_SHORT = 0;
public const TITLE_FOCUS_KEYWORD_POSITION = 4;
public const TITLE_IS_HOME = -1;
public const TITLE_NO_FOCUS_KEYWORD = 3; // only checked if the focus keyword has been defined
public const TITLE_OK_BUT_SHORT = 1;
public const TITLE_SUCCESS = 5;
public const TITLE_TOO_LONG = 2;
public const TITLE_TOO_SHORT = 0;

/**
* @return array
Expand Down
4 changes: 2 additions & 2 deletions src/Analysis/WordCountAnalysis.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
*/
class WordCountAnalysis extends Analysis
{
const WORD_COUNT_ABOVE_MIN = 1;
const WORD_COUNT_BELOW_MIN = 0;
public const WORD_COUNT_ABOVE_MIN = 1;
public const WORD_COUNT_BELOW_MIN = 0;

/**
* @return int
Expand Down
23 changes: 7 additions & 16 deletions src/Builders/FacebookMetaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,11 +136,9 @@ public function process()
}

/**
* @param mixed $description
*
* @return FacebookMetaGenerator
*/
public function setDescription($description)
public function setDescription(mixed $description)
{
$this->description = $description;
return $this;
Expand Down Expand Up @@ -172,13 +170,11 @@ public function setImageHeight($height)
}

/**
* @param mixed $imageUrl
*
* @return FacebookMetaGenerator
*/
public function setImageUrl($imageUrl)
public function setImageUrl(mixed $imageUrl)
{
if ($imageUrl && (substr($imageUrl, 0, 1) === '/' || substr($imageUrl, 0, 4) !== 'http')) {
if ($imageUrl && (str_starts_with($imageUrl, '/') || !str_starts_with($imageUrl, 'http'))) {
throw new \InvalidArgumentException(
'A relative or invalid URL was detected; you must provide the full absolute URL'
);
Expand All @@ -200,23 +196,20 @@ public function setImageWidth($width)
}

/**
* @param mixed $title
*
* @return FacebookMetaGenerator
*/
public function setTitle($title)
public function setTitle(mixed $title)
{
$this->title = $title;
return $this;
}

/**
* @param mixed $type
*
* @return FacebookMetaGenerator
* @throws \Exception
*/
public function setType($type)
public function setType(mixed $type)
{
if (!in_array($type, array_keys(static::getValidTypes()))) {
throw new \Exception(sprintf(
Expand All @@ -231,13 +224,11 @@ public function setType($type)
}

/**
* @param mixed $url
*
* @return FacebookMetaGenerator
*/
public function setUrl($url)
public function setUrl(mixed $url)
{
if ($url && (substr($url, 0, 1) === '/' || substr($url, 0, 4) !== 'http')) {
if ($url && (str_starts_with($url, '/') || !str_starts_with($url, 'http'))) {
throw new \InvalidArgumentException(
'A relative URL was detected; you must provide the full absolute URL instead'
);
Expand Down
14 changes: 4 additions & 10 deletions src/Builders/TwitterMetaGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,25 +129,21 @@ public function setCreator($creator)
}

/**
* @param mixed $description
*
* @return TwitterMetaGenerator
*/
public function setDescription($description)
public function setDescription(mixed $description)
{
$this->description = $description;

return $this;
}

/**
* @param mixed $imageUrl
*
* @return TwitterMetaGenerator
*/
public function setImageUrl($imageUrl)
public function setImageUrl(mixed $imageUrl)
{
if ($imageUrl && (substr($imageUrl, 0, 1) === '/' || substr($imageUrl, 0, 4) !== 'http')) {
if ($imageUrl && (str_starts_with($imageUrl, '/') || !str_starts_with($imageUrl, 'http'))) {
throw new \InvalidArgumentException(
'A relative or invalid URL was detected, your must provide the full absolute URL'
);
Expand All @@ -158,11 +154,9 @@ public function setImageUrl($imageUrl)
}

/**
* @param mixed $title
*
* @return TwitterMetaGenerator
*/
public function setTitle($title)
public function setTitle(mixed $title)
{
$this->title = $title;

Expand Down
5 changes: 3 additions & 2 deletions src/Extensions/PageHealthExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace QuinnInteractive\Seo\Extensions;

use SilverStripe\ErrorPage\ErrorPage;
use KubAT\PhpSimple\HtmlDomParser;
use QuinnInteractive\Seo\Forms\GoogleSearchPreview;
use QuinnInteractive\Seo\Forms\HealthAnalysisField;
Expand All @@ -22,7 +23,7 @@
*/
class PageHealthExtension extends DataExtension
{
const EMPTY_HTML = '<p></p>';
public const EMPTY_HTML = '<p></p>';

private static $tab_name = 'Root.Seo';

Expand Down Expand Up @@ -109,7 +110,7 @@ public function updateCMSFields(FieldList $fields)
return;
}

if (class_exists('\SilverStripe\ErrorPage\ErrorPage') && $this->owner instanceof \SilverStripe\ErrorPage\ErrorPage) {
if (class_exists('\SilverStripe\ErrorPage\ErrorPage') && $this->owner instanceof ErrorPage) {
return;
}

Expand Down
3 changes: 2 additions & 1 deletion src/Forms/GoogleSearchPreview.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace QuinnInteractive\Seo\Forms;

use SilverStripe\Forms\FormField;
use QuinnInteractive\Seo\Extensions\PageHealthExtension;
use QuinnInteractive\Seo\Extensions\PageSeoExtension;
use SilverStripe\Control\Controller;
Expand Down Expand Up @@ -32,7 +33,7 @@ class GoogleSearchPreview extends LiteralField
* HealthAnalysisField constructor.
*
* @param string $name
* @param \SilverStripe\Forms\FormField|string $title
* @param FormField|string $title
* @param \Page|PageHealthExtension|PageSeoExtension $page
* @param simple_html_dom $domParser
*/
Expand Down
3 changes: 2 additions & 1 deletion src/Forms/HealthAnalysisField.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace QuinnInteractive\Seo\Forms;

use SilverStripe\Forms\FormField;
use QuinnInteractive\Seo\Analysis\Analysis;
use QuinnInteractive\Seo\Extensions\PageHealthExtension;
use SilverStripe\CMS\Model\SiteTree;
Expand Down Expand Up @@ -35,7 +36,7 @@ class HealthAnalysisField extends LiteralField
* HealthAnalysisField constructor.
*
* @param string $name
* @param \SilverStripe\Forms\FormField|string $title
* @param FormField|string $title
* @param \Page $page
*/
public function __construct($name, $title, SiteTree $page)
Expand Down
4 changes: 2 additions & 2 deletions src/Seo.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static function getFacebookMetaTags($owner)

$generator = FacebookMetaGenerator::create();
$generator->setTitle($owner->FacebookPageTitle ?: $owner->Title);
$generator->setDescription($owner->FacebookPageDescription ?: $owner->MetaDescription ?: $owner->Content);
$generator->setDescription(($owner->FacebookPageDescription ?: $owner->MetaDescription) ?: $owner->Content);
$generator->setImageUrl(($owner->FacebookPageImage()->exists())
? $owner->FacebookPageImage()->AbsoluteLink()
: null);
Expand Down Expand Up @@ -166,7 +166,7 @@ public static function getTwitterMetaTags($owner)
{
$generator = TwitterMetaGenerator::create();
$generator->setTitle($owner->TwitterPageTitle ?: $owner->Title);
$generator->setDescription($owner->TwitterPageDescription ?: $owner->MetaDescription ?: $owner->Content);
$generator->setDescription(($owner->TwitterPageDescription ?: $owner->MetaDescription) ?: $owner->Content);
$generator->setImageUrl(($owner->TwitterPageImage()->exists())
? $owner->TwitterPageImage()->AbsoluteLink()
: null);
Expand Down
11 changes: 7 additions & 4 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
<?php

if (!class_exists('Page') && class_exists('\SilverStripe\CMS\Model\SiteTree')) {
class Page extends \SilverStripe\CMS\Model\SiteTree
use SilverStripe\CMS\Model\SiteTree;
use SilverStripe\CMS\Controllers\ContentController;

if (!class_exists('Page') && class_exists(SiteTree::class)) {
class Page extends SiteTree
{
private static $table_name = 'Page';

Expand All @@ -11,8 +14,8 @@ class Page extends \SilverStripe\CMS\Model\SiteTree
}
}

if (!class_exists('PageController') && class_exists('\SilverStripe\CMS\Controllers\ContentController')) {
class PageController extends \SilverStripe\CMS\Controllers\ContentController
if (!class_exists('PageController') && class_exists(ContentController::class)) {
class PageController extends ContentController
{
}
}
Expand Down

0 comments on commit 69834f7

Please sign in to comment.