Skip to content

Commit

Permalink
Required phlak/coding-standards for development and applied automated…
Browse files Browse the repository at this point in the history
… fixes
  • Loading branch information
PHLAK committed Nov 25, 2020
1 parent 2161316 commit 5c19fca
Show file tree
Hide file tree
Showing 21 changed files with 67 additions and 313 deletions.
32 changes: 4 additions & 28 deletions .php_cs.dist
Original file line number Diff line number Diff line change
@@ -1,34 +1,10 @@
<?php

require __DIR__ . '/vendor/autoload.php';

$finder = PhpCsFixer\Finder::create()->in([
__DIR__ . DIRECTORY_SEPARATOR . 'src',
__DIR__ . DIRECTORY_SEPARATOR . 'tests'
__DIR__ . DIRECTORY_SEPARATOR . 'tests',
]);

return PhpCsFixer\Config::create()
->setRules([
'@PSR1' => true,
'@PSR2' => true,
'@Symfony' => true,
'array_syntax' => [
'syntax' => 'short'
],
'concat_space' => [
'spacing' => 'one'
],
'increment_style' => null,
'linebreak_after_opening_tag' => true,
'new_with_braces' => false,
'no_multiline_whitespace_before_semicolons' => true,
'no_superfluous_phpdoc_tags' => false,
'no_useless_else' => true,
'no_useless_return' => true,
'not_operator_with_successor_space' => true,
'ordered_imports' => true,
'phpdoc_no_empty_return' => false,
'phpdoc_order' => true,
'semicolon_after_instruction' => true,
'single_trait_insert_per_statement' => false,
'trailing_comma_in_multiline_array' => false,
'yoda_style' => false
])->setFinder($finder);
return PHLAK\CodingStandards\ConfigFactory::make($finder);
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"require-dev": {
"php": ">=7.4",
"friendsofphp/php-cs-fixer": "^2.16.1",
"phlak/coding-standards": "^1.1",
"phpunit/phpunit": "^9.1",
"psy/psysh": "^0.10",
"vimeo/psalm": "^4.2"
Expand Down
2 changes: 0 additions & 2 deletions src/Config/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ abstract class Config
* @param mixed $option A given option
*
* @throws \PHLAK\Twine\Exceptions\ConfigException
*
* @return void
*/
public static function validateOption($option)
{
Expand Down
8 changes: 1 addition & 7 deletions src/Config/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ class Str
* Set the default internal character encoding.
*
* @param string $encoding The desired character encoding
*
* @return void
*/
public static function setEncoding(string $encoding)
{
Expand All @@ -25,11 +23,7 @@ public static function setEncoding(string $encoding)
self::$encoding = $encoding;
}

/**
* Get the default internal character encoding.
*
* @return string
*/
/** Get the default internal character encoding. */
public static function getEncoding(): string
{
return self::$encoding;
Expand Down
6 changes: 3 additions & 3 deletions src/Config/Trim.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

final class Trim extends Config
{
const BOTH = 'trim';
const LEFT = 'ltrim';
const RIGHT = 'rtrim';
public const BOTH = 'trim';
public const LEFT = 'ltrim';
public const RIGHT = 'rtrim';
}
24 changes: 4 additions & 20 deletions src/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Str implements \ArrayAccess, \JsonSerializable, \Serializable
/**
* Create a new Str object.
*
* @param mixed $string A string
* @param mixed $string A string
* @param string $encoding The internal encoding
*
* @return \PHLAK\Twine\Str
Expand All @@ -53,39 +53,25 @@ public function __toString(): string
* Static make constructor.
*
* @param mixed ...$parameters The parameters
*
* @return self
*/
public static function make(...$parameters): self
{
return new static(...$parameters);
}

/**
* Returns the object as a string when json_encode is called.
*
* @return string
*/
/** Returns the object as a string when json_encode is called. */
public function jsonSerialize(): string
{
return $this->string;
}

/**
* Serialize the string.
*
* @return string
*/
/** Serialize the string. */
public function serialize(): string
{
return serialize($this->string);
}

/**
* Unserialize the string.
*
* @return void
*/
/** Unserialize the string. */
public function unserialize($serialized)
{
$this->string = unserialize($serialized);
Expand All @@ -95,8 +81,6 @@ public function unserialize($serialized)
* Set the internal character encoding.
*
* @param string $encoding The desired character encoding
*
* @return self
*/
public function encoding(string $encoding): self
{
Expand Down
4 changes: 0 additions & 4 deletions src/Support/Str.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ class Str
* Split a string into an array of characters.
*
* @param string $string A String
*
* @return array
*/
public static function characters(string $string): array
{
Expand All @@ -20,8 +18,6 @@ public static function characters(string $string): array
* Split an string into an array of words.
*
* @param string $string A String
*
* @return array
*/
public static function words(string $string): array
{
Expand Down
78 changes: 13 additions & 65 deletions src/Traits/Aliases.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ trait Aliases
* Return a number of characters from the start of the string.
*
* @param int $count The number of characters to be returned
*
* @return self
*/
public function first(int $count): self
{
Expand All @@ -22,49 +20,31 @@ public function first(int $count): self
* Return a number of characters from the end of the string.
*
* @param int $count The number of characters to be returned
*
* @return self
*/
public function last(int $count): self
{
return $this->substring(-$count);
}

/**
* Encode the string to base64.
*
* @return self
*/
/** Encode the string to base64. */
public function base64Encode(): self
{
return $this->base64(Config\Base64::ENCODE);
}

/**
* Decode the base64 encoded string.
*
* @return self
*/
/** Decode the base64 encoded string. */
public function base64Decode(): self
{
return $this->base64(Config\Base64::DECODE);
}

/**
* Encode the string to hex.
*
* @return self
*/
/** Encode the string to hex. */
public function hexEncode(): self
{
return $this->hex(Config\Hex::ENCODE);
}

/**
* Decode the hex encoded string.
*
* @return self
*/
/** Decode the hex encoded string. */
public function hexDecode(): self
{
return $this->hex(Config\Hex::DECODE);
Expand All @@ -75,8 +55,6 @@ public function hexDecode(): self
* the string.
*
* @param string $mask A list of characters to be stripped (default: " \t\n\r\0\x0B")
*
* @return self
*/
public function trimLeft(string $mask = " \t\n\r\0\x0B"): self
{
Expand All @@ -87,49 +65,31 @@ public function trimLeft(string $mask = " \t\n\r\0\x0B"): self
* Remove whitespace or a specific set of characters from the end of the string.
*
* @param string $mask A list of characters to be stripped (default: " \t\n\r\0\x0B")
*
* @return self
*/
public function trimRight(string $mask = " \t\n\r\0\x0B"): self
{
return $this->trim($mask, Config\Trim::RIGHT);
}

/**
* Convert the first character of the string to uppercase.
*
* @return self
*/
/** Convert the first character of the string to uppercase. */
public function uppercaseFirst(): self
{
return $this->uppercase(Config\Uppercase::FIRST);
}

/**
* Convert the first character of each word in the string to uppercase.
*
* @return self
*/
/** Convert the first character of each word in the string to uppercase. */
public function uppercaseWords(): self
{
return $this->uppercase(Config\Uppercase::WORDS);
}

/**
* Convert the first letter of the string to lowercase.
*
* @return self
*/
/** Convert the first letter of the string to lowercase. */
public function lowercaseFirst(): self
{
return $this->lowercase(Config\Lowercase::FIRST);
}

/**
* Convert the first letter of the string to lowercase.
*
* @return self
*/
/** Convert the first letter of the string to lowercase. */
public function lowercaseWords(): self
{
return $this->lowercase(Config\Lowercase::WORDS);
Expand All @@ -139,10 +99,8 @@ public function lowercaseWords(): self
* Wrap the string after the first whitespace character after a given number
* of characters.
*
* @param int $width Number of characters at which to wrap
* @param int $width Number of characters at which to wrap
* @param string $break Character used to break the string
*
* @return self
*/
public function wrapSoft(int $width, string $break = "\n"): self
{
Expand All @@ -152,10 +110,8 @@ public function wrapSoft(int $width, string $break = "\n"): self
/**
* Wrap the string after an exact number of characters.
*
* @param int $width Number of characters at which to wrap
* @param int $width Number of characters at which to wrap
* @param string $break Character used to break the string
*
* @return self
*/
public function wrapHard($width, $break = "\n"): self
{
Expand All @@ -165,10 +121,8 @@ public function wrapHard($width, $break = "\n"): self
/**
* Pad right side of the string to a specific length.
*
* @param int $length Length to pad the string to
* @param int $length Length to pad the string to
* @param string $padding Character to pad the string with
*
* @return self
*/
public function padRight(int $length, string $padding = ' '): self
{
Expand All @@ -178,10 +132,8 @@ public function padRight(int $length, string $padding = ' '): self
/**
* Pad left side of the string to a specific length.
*
* @param int $length Length to pad the string to
* @param int $length Length to pad the string to
* @param string $padding Character to pad the string with
*
* @return self
*/
public function padLeft(int $length, string $padding = ' '): self
{
Expand All @@ -191,10 +143,8 @@ public function padLeft(int $length, string $padding = ' '): self
/**
* Pad both sides of the string to a specific length.
*
* @param int $length Length to pad the string to
* @param int $length Length to pad the string to
* @param string $padding Character to pad the string with
*
* @return self
*/
public function padBoth(int $length, string $padding = ' '): self
{
Expand All @@ -205,8 +155,6 @@ public function padBoth(int $length, string $padding = ' '): self
* Determine if the string matches another string regardless of case.
*
* @param string $string The string to compare against
*
* @return bool
*/
public function insensitiveMatch(string $string): bool
{
Expand Down
10 changes: 2 additions & 8 deletions src/Traits/ArrayAccess.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,6 @@ trait ArrayAccess
* Determine whether a character exists in the string at a specific offset.
*
* @param int $offset Offset to check for existence
*
* @return bool
*/
public function offsetExists($offset): bool
{
Expand All @@ -32,12 +30,10 @@ public function offsetGet($offset)
/**
* Not implemented due to immutability.
*
* @param int $offset Not implemented
* @param mixed $value Not implemented
* @param int $offset Not implemented
* @param mixed $value Not implemented
*
* @throws \RuntimeException
*
* @return void
*/
public function offsetSet($offset, $value)
{
Expand All @@ -50,8 +46,6 @@ public function offsetSet($offset, $value)
* @param int $offset Not implemented
*
* @throws \RuntimeException
*
* @return void
*/
public function offsetUnset($offset)
{
Expand Down
Loading

0 comments on commit 5c19fca

Please sign in to comment.