Skip to content

Commit

Permalink
Formatted method argument spacing
Browse files Browse the repository at this point in the history
Signed-off-by: Tom Wright <[email protected]>
  • Loading branch information
betterthanclay committed Nov 3, 2023
1 parent 2a45c0d commit fa8178e
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 66 deletions.
5 changes: 3 additions & 2 deletions src/Plugins/Number.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ class Number implements NumberPlugin
/**
* Init with parent Context
*/
public function __construct(Context $context)
{
public function __construct(
Context $context
) {
$this->context = $context;
}

Expand Down
5 changes: 3 additions & 2 deletions src/Plugins/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ class Time implements TimePlugin
/**
* Init with parent Context
*/
public function __construct(Context $context)
{
public function __construct(
Context $context
) {
$this->context = $context;
}

Expand Down
157 changes: 95 additions & 62 deletions src/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,8 +102,9 @@ public function getEncoding(): string
/**
* Convert encoding
*/
public function convertEncoding(string $encoding): static
{
public function convertEncoding(
string $encoding
): static {
if ($encoding === $this->encoding) {
return $this;
}
Expand All @@ -128,16 +129,19 @@ public function toUtf8(): static
/**
* Get a single char at index
*/
public function getChar(int $index): static
{
public function getChar(
int $index
): static {
return $this->slice($index, 1);
}

/**
* Replace a single char
*/
public function replaceChar(int $index, string $char): static
{
public function replaceChar(
int $index,
string $char
): static {
$output = '';

if ($index !== 0) {
Expand All @@ -156,8 +160,10 @@ public function replaceChar(int $index, string $char): static
/**
* Insert a string into the text
*/
public function insert(int $index, string $string): static
{
public function insert(
int $index,
string $string
): static {
$output = '';

if ($index !== 0) {
Expand All @@ -173,8 +179,9 @@ public function insert(int $index, string $string): static
/**
* Remove a single char
*/
public function removeChar(int $index): static
{
public function removeChar(
int $index
): static {
$output = '';

if ($index !== 0) {
Expand All @@ -191,8 +198,9 @@ public function removeChar(int $index): static
/**
* Check char index
*/
public function hasCharAt(int $index): bool
{
public function hasCharAt(
int $index
): bool {
return mb_substr($this->text, $index, 1, $this->encoding) !== '';
}

Expand All @@ -202,8 +210,9 @@ public function hasCharAt(int $index): bool
*
* @param int $index
*/
public function offsetGet(mixed $index): static
{
public function offsetGet(
mixed $index
): static {
return $this->slice($index, 1);
}

Expand All @@ -227,8 +236,9 @@ public function offsetSet(
*
* @param int $index
*/
public function offsetExists(mixed $index): bool
{
public function offsetExists(
mixed $index
): bool {
return $this->hasCharAt($index);
}

Expand All @@ -237,8 +247,9 @@ public function offsetExists(mixed $index): bool
*
* @param int $index
*/
public function offsetUnset(mixed $index): void
{
public function offsetUnset(
mixed $index
): void {
throw Exceptional::Implementation(
'Immutable DecodeLabs\\Dictum\\Text does not support array-access unset'
);
Expand Down Expand Up @@ -308,8 +319,9 @@ public function getLastIndexOfCi(
/**
* Is $needle in text?
*/
public function contains(string ...$needles): bool
{
public function contains(
string ...$needles
): bool {
foreach ($needles as $needle) {
if (false !== mb_strpos($this->text, $needle, 0, $this->encoding)) {
return true;
Expand All @@ -322,8 +334,9 @@ public function contains(string ...$needles): bool
/**
* Is $needle in text? Case insensitive
*/
public function containsCi(string ...$needles): bool
{
public function containsCi(
string ...$needles
): bool {
foreach ($needles as $needle) {
if (false !== mb_stripos($this->text, $needle, 0, $this->encoding)) {
return true;
Expand All @@ -336,8 +349,9 @@ public function containsCi(string ...$needles): bool
/**
* Are all $needles in text?
*/
public function containsAll(string ...$needles): bool
{
public function containsAll(
string ...$needles
): bool {
foreach ($needles as $needle) {
if (false === mb_strpos($this->text, $needle, 0, $this->encoding)) {
return false;
Expand All @@ -350,8 +364,9 @@ public function containsAll(string ...$needles): bool
/**
* Are all $needles in text? Case insensitive
*/
public function containsAllCi(string ...$needles): bool
{
public function containsAllCi(
string ...$needles
): bool {
foreach ($needles as $needle) {
if (false === mb_stripos($this->text, $needle, 0, $this->encoding)) {
return false;
Expand All @@ -366,8 +381,9 @@ public function containsAllCi(string ...$needles): bool
/**
* Does the end of the text match $start?
*/
public function beginsWith(string ...$starts): bool
{
public function beginsWith(
string ...$starts
): bool {
foreach ($starts as $start) {
if (mb_substr(
$this->text,
Expand All @@ -385,8 +401,9 @@ public function beginsWith(string ...$starts): bool
/**
* Does the end of the text match $start?
*/
public function beginsWithCi(string ...$starts): bool
{
public function beginsWithCi(
string ...$starts
): bool {
foreach ($starts as $start) {
if (mb_strtolower(
mb_substr(
Expand All @@ -407,8 +424,9 @@ public function beginsWithCi(string ...$starts): bool
/**
* Does the end of the text match $end?
*/
public function endsWith(string ...$ends): bool
{
public function endsWith(
string ...$ends
): bool {
foreach ($ends as $end) {
if (mb_substr(
$this->text,
Expand All @@ -426,8 +444,9 @@ public function endsWith(string ...$ends): bool
/**
* Does the end of the text match $end?
*/
public function endsWithCi(string ...$ends): bool
{
public function endsWithCi(
string ...$ends
): bool {
foreach ($ends as $end) {
if (mb_strtolower(
mb_substr(
Expand Down Expand Up @@ -503,16 +522,18 @@ public function padBoth(
/**
* Count instances of $string
*/
public function countInstances(string $string): int
{
public function countInstances(
string $string
): int {
return mb_substr_count($this->text, $string, $this->encoding);
}

/**
* Count case insensitive instances of $string
*/
public function countInstancesCi(string $string): int
{
public function countInstancesCi(
string $string
): int {
return mb_substr_count(
mb_strtolower($this->text, $this->encoding),
mb_strtolower($string, $this->encoding),
Expand Down Expand Up @@ -550,8 +571,9 @@ public function slice(
/**
* Get random slice
*/
public function sliceRandom(int $length): static
{
public function sliceRandom(
int $length
): static {
$total = $this->getLength();

if ($length >= $total) {
Expand Down Expand Up @@ -786,8 +808,9 @@ public function regexSplit(
/**
* Replace whitespace with $delimiter, all lowercase
*/
public function delimit(string $delimiter): static
{
public function delimit(
string $delimiter
): static {
$encoding = mb_regex_encoding();
mb_regex_encoding($this->encoding);

Expand All @@ -806,26 +829,29 @@ public function delimit(string $delimiter): static
/**
* Trim left and right
*/
public function trim(string $chars = null): static
{
public function trim(
string $chars = null
): static {
$chars = $chars ? preg_quote($chars) : '[:space:]';
return $this->regexReplace('^[' . $chars . ']+|[' . $chars . ']+$', '');
}

/**
* Trim left
*/
public function trimLeft(string $chars = null): static
{
public function trimLeft(
string $chars = null
): static {
$chars = $chars ? preg_quote($chars) : '[:space:]';
return $this->regexReplace('^[' . $chars . ']+', '');
}

/**
* Trim right
*/
public function trimRight(string $chars = null): static
{
public function trimRight(
string $chars = null
): static {
$chars = $chars ? preg_quote($chars) : '[:space:]';
return $this->regexReplace('[' . $chars . ']+$', '');
}
Expand Down Expand Up @@ -1046,8 +1072,9 @@ public function toAscii(
/**
* Convert text value to boolean
*/
public function toBoolean(?bool $default = null): bool
{
public function toBoolean(
?bool $default = null
): bool {
switch ($text = strtolower(trim($this->text))) {
case 'false':
case '0':
Expand Down Expand Up @@ -1081,8 +1108,9 @@ public function toBoolean(?bool $default = null): bool
/**
* Convert tabs to spaces
*/
public function tabsToSpaces(int $tabLength = 4): static
{
public function tabsToSpaces(
int $tabLength = 4
): static {
return new static(
str_replace("\t", str_repeat(' ', $tabLength), $this->text),
$this->encoding
Expand All @@ -1092,8 +1120,9 @@ public function tabsToSpaces(int $tabLength = 4): static
/**
* Convert spaces to tabs
*/
public function spacesToTabs(int $tabLength): static
{
public function spacesToTabs(
int $tabLength
): static {
return new static(
str_replace(str_repeat(' ', $tabLength), "\t", $this->text),
$this->encoding
Expand All @@ -1104,8 +1133,9 @@ public function spacesToTabs(int $tabLength): static
/**
* Convert numerics to alpha characters
*/
public static function numericToAlpha(int $number): static
{
public static function numericToAlpha(
int $number
): static {
static $alphabet = 'abcdefghijklmnopqrstuvwxyz';
$output = '';

Expand Down Expand Up @@ -1154,8 +1184,9 @@ public function alphaToNumeric(): ?int
/**
* Encode for HTML
*/
public function htmlEncode(int $flags = ENT_COMPAT): static
{
public function htmlEncode(
int $flags = ENT_COMPAT
): static {
return new static(
htmlentities($this->text, $flags, $this->encoding),
$this->encoding
Expand All @@ -1165,8 +1196,9 @@ public function htmlEncode(int $flags = ENT_COMPAT): static
/**
* Decode from HTML
*/
public function htmlDecode(int $flags = ENT_COMPAT): static
{
public function htmlDecode(
int $flags = ENT_COMPAT
): static {
return new static(
html_entity_decode($this->text, $flags, $this->encoding),
$this->encoding
Expand All @@ -1177,8 +1209,9 @@ public function htmlDecode(int $flags = ENT_COMPAT): static
/**
* Remove html tags
*/
public function stripTags(string $allowableTags = null): static
{
public function stripTags(
string $allowableTags = null
): static {
if ($allowableTags !== null) {
$output = strip_tags($this->text, $allowableTags);
} else {
Expand Down

0 comments on commit fa8178e

Please sign in to comment.