Method migrate
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function migrate($oldHandle = 'seo', $newHandle = 'newSeo', $siteId = null, $titleSeperator = null)
{
$this->titleSeperator = $titleSeperator;
$query = Entry::find();
$sites = [];
Function migrate
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function migrate($oldHandle = 'seo', $newHandle = 'newSeo', $siteId = null, $titleSeperator = null)
{
$this->titleSeperator = $titleSeperator;
$query = Entry::find();
$sites = [];
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The method migrate uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$sites = Craft::$app->getSites()->getAllSites();
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\yii\helpers\Console' in method 'migrate'. Open
Console::startProgress(0, $total);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\yii\helpers\Console' in method 'migrate'. Open
Console::updateProgress($done, $total);
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method getMarkup uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return !empty($string) ? $string : null;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid using static access to class '\yii\helpers\Console' in method 'migrate'. Open
Console::endProgress();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
Avoid using static access to class '\craft\elements\Entry' in method 'migrate'. Open
$query = Entry::find();
- Read upRead up
- Exclude checks
StaticAccess
Since: 1.4.0
Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.
Example
class Foo
{
public function bar()
{
Bar::baz();
}
}
Source https://phpmd.org/rules/cleancode.html#staticaccess
The method getTitle uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$oldTitle = $this->getMarkup($data->getTitle());
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Reference to instance property title
from undeclared class \craft\elements\Entry
Open
echo "Error updating '$entry->title'";
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$site = Craft::$app->getSites()->getSiteById($siteId);
- Exclude checks
Parameter $data
has undeclared type \ether\seo\models\data\SeoData
Open
private function getTitle(SeoData $data)
- Exclude checks
Parameter $entry
has undeclared type \craft\elements\Entry
Open
private function migrateContent(Entry $entry, $field, $newHandle)
- Exclude checks
Call to method find
from undeclared class \craft\elements\Entry
Open
$query = Entry::find();
- Exclude checks
Reference to instance property titleRaw
from undeclared class \ether\seo\models\data\SeoData
Open
$oldTitle = $data->titleRaw[1];
- Exclude checks
Call to method getTitle
from undeclared class \ether\seo\models\data\SeoData
Open
$oldTitle = $this->getMarkup($data->getTitle());
- Exclude checks
Call to method __toString
from undeclared class \Twig\Markup
Open
return !empty($string->__toString()) ? $string->__toString() : null;
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
if (!Craft::$app->getElements()->saveElement($entry)) {
- Exclude checks
Checking instanceof against undeclared class \Twig\Markup
Open
if ($string instanceof Markup or (is_object($string) && get_class($string) == 'Twig\Markup')) {
- Exclude checks
Call to method updateProgress
from undeclared class \yii\helpers\Console
Open
Console::updateProgress($done, $total);
- Exclude checks
Call to method setFieldValue
from undeclared class \craft\elements\Entry
Open
$entry->setFieldValue($newHandle, $newField);
- Exclude checks
Possibly zero references to use statement for classlike/namespace SocialData
(\ether\seo\models\data\SocialData)
Open
use ether\seo\models\data\SocialData;
- Exclude checks
Call to method __construct
from undeclared class \craft\errors\SiteNotFoundException
Open
throw new SiteNotFoundException("Site with id '$siteId' not found.");
- Exclude checks
Reference to static property app
from undeclared class \Craft
Open
$sites = Craft::$app->getSites()->getAllSites();
- Exclude checks
Call to method startProgress
from undeclared class \yii\helpers\Console
Open
Console::startProgress(0, $total);
- Exclude checks
Call to method endProgress
from undeclared class \yii\helpers\Console
Open
Console::endProgress();
- Exclude checks
Class extends undeclared class \craft\base\Component
Open
class Ether extends Component
- Exclude checks
Reference to instance property titleRaw
from undeclared class \ether\seo\models\data\SeoData
Open
if (count($data->titleRaw)) {
- Exclude checks