Skip to content

Commit

Permalink
Version 2.2.0
Browse files Browse the repository at this point in the history
With rector 1.0
  • Loading branch information
davidhirtz committed Feb 29, 2024
1 parent 68162ee commit 3935ede
Show file tree
Hide file tree
Showing 18 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
## 2.2.0 (Feb 28, 2024)
## 2.2.0 (Feb 29, 2024)

- Changed `AuthClientSignupForm` and `davidhirtz\yii2\skeleton\modules\admin\models\forms\UserForm` to extend
from `Model` instead of `User` (Issue #21)
Expand Down
2 changes: 1 addition & 1 deletion src/controllers/traits/AjaxRouteTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ protected function registerAjaxRouteDocumentTitle(): void
{
$view = $this->getView();

$title = addslashes(preg_replace("/[\r|\n]/", '', $view->getDocumentTitle()));
$title = addslashes((string) preg_replace("/[\r|\n]/", '', $view->getDocumentTitle()));
$view->registerJs("document.title=\"$title\";", $view::POS_END);
}
}
2 changes: 1 addition & 1 deletion src/helpers/FileHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public static function generateRandomFilename(?string $extension = null, int $le

public static function getExtensionFromUrl(string $url): string
{
return strtolower(pathinfo(parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION));
return strtolower(pathinfo((string) parse_url($url, PHP_URL_PATH), PATHINFO_EXTENSION));
}

public static function encodeUrl(string $url): string
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/Html.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,14 +153,14 @@ public static function nl2br(string $text): string
*/
public static function minify(string $html): string
{
return trim(preg_replace('/>\s+</', '><', $html));
return trim((string) preg_replace('/>\s+</', '><', $html));
}

public static function markKeywords(string $text, array|string|null $keywords, bool $wordBoundary = false): string
{
if ($keywords) {
foreach ((array)$keywords as $keyword) {
$text = preg_replace('~(' . ($wordBoundary ? '\b' : '') . preg_quote((string)$keyword) . ')~ui', '<mark>$1</mark>', $text);
$text = preg_replace('~(' . ($wordBoundary ? '\b' : '') . preg_quote((string)$keyword) . ')~ui', '<mark>$1</mark>', (string) $text);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public static function getSvgDimensions(string $filename): array|bool
if ($attributes->width && $attributes->height) {
$dimensions[0] = (int)$attributes->width;
$dimensions[1] = (int)$attributes->height;
} elseif (preg_match('/(\d+(\.\d+)?) (\d+(\.\d+)?)$/', $attributes->viewBox, $match)) {
} elseif (preg_match('/(\d+(\.\d+)?) (\d+(\.\d+)?)$/', (string) $attributes->viewBox, $match)) {
$viewBox = explode(' ', $match[0]);
$dimensions[0] = (int)$viewBox[0];
$dimensions[1] = (int)$viewBox[1];
Expand Down
2 changes: 1 addition & 1 deletion src/models/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ public function getId(): mixed

public function getInitials(): string
{
return $this->first_name && $this->last_name ? ($this->first_name[0] . $this->last_name[0]) : substr($this->name, 0, 2);
return $this->first_name && $this->last_name ? ($this->first_name[0] . $this->last_name[0]) : substr((string) $this->name, 0, 2);
}

public function getEmailConfirmationUrl(): ?string
Expand Down
2 changes: 1 addition & 1 deletion src/models/traits/MaterializedTreeTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ public function setDescendants(array $descendants): void
$this->_descendants = [];

foreach ($descendants as $descendant) {
$path = $descendant->path ? substr($descendant->path, 0, $length) : null;
$path = $descendant->path ? substr((string) $descendant->path, 0, $length) : null;

if ($path === $this->path) {
$this->_descendants[$descendant->id] = $descendant;
Expand Down
2 changes: 1 addition & 1 deletion src/modules/admin/widgets/navs/TrailSubmenu.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function getTrailModelAdminRoute(): array|false

return [
...$route,
'language' => explode('::', $behavior->modelClass)[1] ?? null
'language' => explode('::', (string) $behavior->modelClass)[1] ?? null
];
}

Expand Down
2 changes: 1 addition & 1 deletion src/validators/CurrencyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function init(): void
$this->thousandSeparator = $matches[3];

// Remove UTF-8 whitespaces and quote for regular expression.
$matches = array_map(fn ($v): string => preg_quote(preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', (string)$v)), $matches);
$matches = array_map(fn ($v): string => preg_quote((string) preg_replace('/^[\pZ\pC]+|[\pZ\pC]+$/u', '', (string)$v)), $matches);
$this->currencyPattern = "/^($matches[1])?\s*(-?(?:\d{1,3}(?:$matches[3]\d{3})+|(?!$matches[3])\d*(?!$matches[3]))(?:$matches[4][0-9]+)?)\s*($matches[5])?$/iu";
} else {
throw new InvalidConfigException("Currency format \"$format\" could not be parsed.");
Expand Down
34 changes: 17 additions & 17 deletions src/validators/HtmlValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,48 +183,48 @@ public function validateAttribute($model, $attribute): void
$html = preg_replace("#\n?<(blockquote|ol|ul)>#i", "\n\n<$1>", $html);

//Fix HtmlPurifier "AutoFormat.AutoParagraph" not applying paragraphs to rows consisting of whitespaces.
$html = preg_replace("#\n\s+\n#i", "\n\n", $html);
$html = preg_replace("#\n\s+\n#i", "\n\n", (string) $html);

// Process html.
$html = HtmlPurifier::process($html, $this->purifierOptions);

// Change invalid break tags.
$html = preg_replace('#<br />#', '<br>', $html);
$html = preg_replace('#\s<br>#', '<br>', $html);
$html = preg_replace('#\s<br>#', '<br>', (string) $html);

// Add break tags.
$blocks = '(?:div|dl|dd|dt|ul|ol|li|pre|blockquote|address|style|p|h[1-6]|hr|legend|section|article|aside)';

$html = preg_replace("#(<'.$blocks.'[^>]*>)#", "\n$1", $html);
$html = preg_replace("#(</'.$blocks.'>)#", "$1\n\n", $html);
$html = preg_replace("#(<'.$blocks.'[^>]*>)#", "\n$1", (string) $html);
$html = preg_replace("#(</'.$blocks.'>)#", "$1\n\n", (string) $html);

// Remove multiple breaking whitespaces.
$html = preg_replace('#\s{2,}#', ' ', $html);
$html = preg_replace('#\s{2,}#', ' ', (string) $html);

// Make sure no empty paragraphs were generated.
$html = preg_replace('#<p>\s*</p>#', '', $html);
$html = preg_replace('#<p>\s*</p>#', '', (string) $html);

// Clean breaks.
$html = preg_replace("#(?<!<br>)\s*\n#", "<br>\n", $html);
$html = preg_replace('#(</?' . $blocks . '[^>]*>)\s*<br>#', '$1', $html);
$html = preg_replace('#<br>(\s*</?(?:div|dd|dl|dt|li|ol|p|pre|table|tbody|td|th|tr|ul)[^>]*>)#', '$1', $html);
$html = preg_replace("#(?<!<br>)\s*\n#", "<br>\n", (string) $html);
$html = preg_replace('#(</?' . $blocks . '[^>]*>)\s*<br>#', '$1', (string) $html);
$html = preg_replace('#<br>(\s*</?(?:div|dd|dl|dt|li|ol|p|pre|table|tbody|td|th|tr|ul)[^>]*>)#', '$1', (string) $html);

// Remove empty elements at the beginning and end of paragraphs.
$html = preg_replace("#\n*\s*<p>\n*\s*#", "\n<p>", $html);
$html = preg_replace("#\n*\s*</p>\n*\s*#", "</p>\n", $html);
$html = preg_replace("#\n*\s*<p>\n*\s*#", "\n<p>", (string) $html);
$html = preg_replace("#\n*\s*</p>\n*\s*#", "</p>\n", (string) $html);

// Remove empty elements and <br> added by the WYSIWYG editor at the end and beginning of tables.
$html = preg_replace("#\n*\s*<table>#", '<table>', $html);
$html = preg_replace("#</table><br>\n*\s*#", '</table>', $html);
$html = preg_replace("#</table>\n*\s*#", '</table>', $html);
$html = preg_replace("#\n*\s*<table>#", '<table>', (string) $html);
$html = preg_replace("#</table><br>\n*\s*#", '</table>', (string) $html);
$html = preg_replace("#</table>\n*\s*#", '</table>', (string) $html);

// Remove whitespaces in lists.
$html = preg_replace("#\n*<li>\s*\n*(.*)\s*\n*</li>#i", "\n<li>$1</li>", $html);
$html = preg_replace("#\n*<li>\s*\n*(.*)\s*\n*</li>#i", "\n<li>$1</li>", (string) $html);

// Add line breaks to closing list tags.
$html = preg_replace("#\n*(</?ul>|</?ol>)\n*#i", "\n$1\n", $html);
$html = preg_replace("#\n*(</?ul>|</?ol>)\n*#i", "\n$1\n", (string) $html);

// Done.
$model->setAttribute($attribute, trim($html));
$model->setAttribute($attribute, trim((string) $html));
}
}
2 changes: 1 addition & 1 deletion src/validators/TimeValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function validateAttribute($model, $attribute): void
// Removes trailing seconds
$value = (string)$model->$attribute;
$value = strlen($value) === 8 ? preg_replace('/:00$/', '', $value) : $value;
$strlen = strlen($value);
$strlen = strlen((string) $value);

if ($strlen === 1) {
$value = "0{$value}00";
Expand Down
2 changes: 1 addition & 1 deletion src/web/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ protected function setDefaultCookieConfig(): void
if ($domain = $this->params['cookieDomain'] ?? false) {
$hostInfo = trim((string)$domain, '.');

if (str_ends_with($this->getRequest()->getHostInfo(), $hostInfo)) {
if (str_ends_with((string) $this->getRequest()->getHostInfo(), $hostInfo)) {
$config['domain'] = $domain;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/ChunkedUploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function init(): void
{
// Try to get file name from header if it was not set via FILES.
if (!$this->name) {
$this->name = rawurldecode(preg_replace('/(^[^"]+")|("$)/', '', (string)ArrayHelper::getValue($_SERVER, 'HTTP_CONTENT_DISPOSITION')));
$this->name = rawurldecode((string) preg_replace('/(^[^"]+")|("$)/', '', (string)ArrayHelper::getValue($_SERVER, 'HTTP_CONTENT_DISPOSITION')));
}

// Parse the Content-Range header, which is formatted like this:
Expand Down
2 changes: 1 addition & 1 deletion src/web/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function beforeAction($action): bool
public function render($view, $params = []): string
{
$content = parent::render($view, $params);
return $this->spacelessOutput ? trim(preg_replace('/>\s+</', '><', $content)) : $content;
return $this->spacelessOutput ? trim((string) preg_replace('/>\s+</', '><', $content)) : $content;
}

public function error(Model|array|string $value): bool
Expand Down
8 changes: 4 additions & 4 deletions src/web/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function init(): void
$this->cookieValidationKey = Yii::$app->params['cookieValidationKey'] ?? '';
}

if ($this->draftSubdomain && str_contains($this->getHostInfo(), "//$this->draftSubdomain.")) {
if ($this->draftSubdomain && str_contains((string) $this->getHostInfo(), "//$this->draftSubdomain.")) {
$this->_isDraft = true;
}

Expand Down Expand Up @@ -72,7 +72,7 @@ public function getIsAjaxRoute(): bool
public function getProductionHostInfo(): string
{
return $this->getIsDraft()
? str_replace("//$this->draftSubdomain.", '//', $this->getHostInfo())
? str_replace("//$this->draftSubdomain.", '//', (string) $this->getHostInfo())
: $this->getHostInfo();
}

Expand All @@ -82,9 +82,9 @@ public function getProductionHostInfo(): string
*/
public function getDraftHostInfo(): bool|string
{
$this->_draftHostInfo ??= $this->getIsDraft() && $this->draftSubdomain && str_contains($this->getHostInfo(), $this->draftSubdomain)
$this->_draftHostInfo ??= $this->getIsDraft() && $this->draftSubdomain && str_contains((string) $this->getHostInfo(), $this->draftSubdomain)
? $this->getHostInfo()
: ($this->draftSubdomain ? preg_replace('#^((https?://)(www.)?)#', "$2$this->draftSubdomain.", $this->getHostInfo()) : false);
: ($this->draftSubdomain ? preg_replace('#^((https?://)(www.)?)#', "$2$this->draftSubdomain.", (string) $this->getHostInfo()) : false);

return $this->_draftHostInfo;
}
Expand Down
2 changes: 1 addition & 1 deletion src/web/StreamUploadedFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ protected function loadTemporaryFile(): void
return;
}

$this->name = basename(parse_url($this->url, PHP_URL_PATH));
$this->name = basename((string) parse_url($this->url, PHP_URL_PATH));
$this->type = FileHelper::getMimeType($this->tempName);

if ($this->allowedExtensions && !in_array($this->getExtension(), $this->allowedExtensions)) {
Expand Down
6 changes: 3 additions & 3 deletions src/web/UrlManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ protected function setApplicationLanguage(Request $request): void

if ($this->i18nSubdomain) {
$host = parse_url($this->getHostInfo(), PHP_URL_HOST);
$subdomain = explode('.', $host)[$request->getIsDraft() ? 1 : 0];
$subdomain = explode('.', (string) $host)[$request->getIsDraft() ? 1 : 0];

if (in_array($subdomain, $this->languages)) {
Yii::$app->language = $subdomain;
Expand Down Expand Up @@ -243,7 +243,7 @@ public function getImmutableRuleParams(int $position = 0): array

foreach (Yii::$app->getUrlManager()->rules as $rule) {
if ($rule instanceof UrlRule) {
$param = explode('/', $rule->name)[$position];
$param = explode('/', (string) $rule->name)[$position];
if (preg_match('/^\w+$/', $param)) {
$params[] = $param;
} elseif (preg_match('/^<\w+:([\w|]+)>$/', $param, $matches)) {
Expand All @@ -263,7 +263,7 @@ public function getI18nHostInfo(): string
($request->getIsDraft() ? $request->draftSubdomain : 'www') :
($request->getIsDraft() ? ($request->draftSubdomain . '.' . Yii::$app->language) : Yii::$app->language);

return substr(parse_url($this->getHostInfo(), PHP_URL_HOST), strlen((string)$hostInfo));
return substr((string) parse_url($this->getHostInfo(), PHP_URL_HOST), strlen((string)$hostInfo));
}

public function hasI18nUrls(): bool
Expand Down
2 changes: 1 addition & 1 deletion src/web/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function afterLogout($identity): void
private function insertLogin(\davidhirtz\yii2\skeleton\models\User $user): void
{
if ($browser = Yii::$app->getRequest()->getUserAgent()) {
$browser = mb_substr($browser, 0, 255, Yii::$app->charset);
$browser = mb_substr((string) $browser, 0, 255, Yii::$app->charset);
}

if ($ipAddress = ($this->ipAddress ?: Yii::$app->getRequest()->getUserIP())) {
Expand Down

0 comments on commit 3935ede

Please sign in to comment.