Skip to content

Commit

Permalink
Replaced EMPTY_STRING with EMPTY.
Browse files Browse the repository at this point in the history
  • Loading branch information
bbankowski committed Jun 26, 2023
1 parent 59d12ca commit 17ee42a
Show file tree
Hide file tree
Showing 8 changed files with 20 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Support for PHP 8.0 is dropped. Minimal PHP version required is 8.2.

Enhancements:
* [ORM] Added support for count query with `DISTINCT` in PostgreSQL dialect.
* [Utilities] `Strings::EMPTY_STRING` is deprecated in favour of `Strings::EMPTY`.

Release 2.0.0
--------
Expand Down
4 changes: 2 additions & 2 deletions src/Ouzo/Core/Db/Dialect/Dialect.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function select(int $queryType = null): string
{
$type = $queryType ?: $this->query->type;
if ($type == QueryType::$SELECT) {
$distinct = $this->query->distinct ? 'DISTINCT ' : (empty($this->query->distinctOnColumns) ? Strings::EMPTY_STRING : $this->getDistinctOnQuery());
$distinct = $this->query->distinct ? 'DISTINCT ' : (empty($this->query->distinctOnColumns) ? Strings::EMPTY : $this->getDistinctOnQuery());
$columns = empty($this->query->selectColumns) ? '*' : Joiner::on(', ')->map(DialectUtil::addAliases())->join($this->query->selectColumns);
return "SELECT {$distinct}{$columns}";
}
Expand All @@ -36,7 +36,7 @@ public function select(int $queryType = null): string
}
return 'SELECT count(*)';
}
return Strings::EMPTY_STRING;
return Strings::EMPTY;
}

public function update(): string
Expand Down
2 changes: 1 addition & 1 deletion src/Ouzo/Core/Helper/FormHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class FormHelper
{
public static function escapeText(?string $text): ?string
{
return htmlspecialchars($text ?: Strings::EMPTY_STRING, ENT_COMPAT);
return htmlspecialchars($text ?: Strings::EMPTY, ENT_COMPAT);
}

public static function escapeNewLine(?string $text): ?string
Expand Down
6 changes: 3 additions & 3 deletions src/Ouzo/Core/Helper/HtmlElementRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public static function formStart(): HtmlElementRenderer

public function setText(?string $text): HtmlElementRenderer
{
$this->text = htmlspecialchars($text ?? Strings::EMPTY_STRING, ENT_COMPAT);
$this->text = htmlspecialchars($text ?? Strings::EMPTY, ENT_COMPAT);
return $this;
}

Expand Down Expand Up @@ -167,7 +167,7 @@ private function attributesToHtml(array $attributes): string
$attributes = $this->sort($attributes);

$attrs = Arrays::mapEntries($attributes, function ($key, $value) {
$escaped = htmlspecialchars($value ?? Strings::EMPTY_STRING, ENT_COMPAT);
$escaped = htmlspecialchars($value ?? Strings::EMPTY, ENT_COMPAT);
return "$key=\"$escaped\"";
});
return implode(' ', $attrs);
Expand All @@ -190,4 +190,4 @@ private function sort(array $attributes): array
ksort($alphabeticOrderAttrs);
return $fixedOrderAttrs + $alphabeticOrderAttrs;
}
}
}
2 changes: 1 addition & 1 deletion src/Ouzo/Core/Uri/UriGeneratorTemplates.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function replaceTemplate(string $namesList, string $methodsList, s

private static function replace(string $template, string $pattern, ?string $replacement): string
{
$replacement ??= Strings::EMPTY_STRING;
$replacement ??= Strings::EMPTY;
return str_replace(["/*{{$pattern}}*/", "%{{$pattern}}"], $replacement, $template);
}

Expand Down
4 changes: 2 additions & 2 deletions src/Ouzo/Goodies/Utilities/DynamicProxy.php
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private static function generateParameters(ReflectionMethod $reflectionMethod):
$parameter = '';
if ($reflectionParameter->hasType() && $reflectionParameter->getType() instanceof ReflectionNamedType) {
$typeName = $reflectionParameter->getType()->getName();
$nullable = $typeName != 'mixed' && $reflectionParameter->allowsNull() ? '?' : Strings::EMPTY_STRING;
$nullable = $typeName != 'mixed' && $reflectionParameter->allowsNull() ? '?' : Strings::EMPTY;
$parameter .= "{$nullable}{$typeName} ";
}
if ($reflectionParameter->isVariadic()) {
Expand Down Expand Up @@ -160,6 +160,6 @@ private static function generateRelation(string $relation, array $classes): stri
if ($classes) {
return $relation . ' ' . implode(', ', $classes);
}
return Strings::EMPTY_STRING;
return Strings::EMPTY;
}
}
11 changes: 8 additions & 3 deletions src/Ouzo/Goodies/Utilities/Strings.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,12 @@

class Strings
{
const EMPTY_STRING = '';
const EMPTY = '';

/**
* @deprecated Use `Strings::EMPTY` instead.
*/
const EMPTY_STRING = self::EMPTY;

/**
* Example:
Expand All @@ -26,7 +31,7 @@ public static function underscoreToCamelCase(?string $string): ?string
if (is_null($string)) {
return null;
}
return str_replace('_', self::EMPTY_STRING, ucwords($string, '_'));
return str_replace('_', self::EMPTY, ucwords($string, '_'));
}

/**
Expand Down Expand Up @@ -192,7 +197,7 @@ public static function remove(?string $string, ?string $toRemove): ?string
if (is_null($toRemove)) {
return $string;
}
return str_replace($toRemove, self::EMPTY_STRING, $string);
return str_replace($toRemove, self::EMPTY, $string);
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/Ouzo/Goodies/Utilities/ToString/SimpleToStringStyle.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function __construct()
{
$this->setUseClassName(false);
$this->setUseFieldNames(false);
$this->setContentStart(Strings::EMPTY_STRING);
$this->setContentEnd(Strings::EMPTY_STRING);
$this->setContentStart(Strings::EMPTY);
$this->setContentEnd(Strings::EMPTY);
}
}

0 comments on commit 17ee42a

Please sign in to comment.