Skip to content

Commit

Permalink
Added vimeo/psalm to dev dependencies and fixed several static analys…
Browse files Browse the repository at this point in the history
…is issues
  • Loading branch information
PHLAK committed Dec 4, 2019
1 parent 2cb7bd3 commit 277e33e
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 13 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.3",
"phpunit/phpunit": "^6.0 || ^7.0",
"psy/psysh": "^0.9.6"
"psy/psysh": "^0.9.6",
"vimeo/psalm": "^3.6"
},
"autoload": {
"psr-4": {
Expand Down
55 changes: 55 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>

<issueHandlers>
<LessSpecificReturnType errorLevel="info" />

<!-- level 3 issues - slightly lazy code writing, but provably low false-negatives -->

<DeprecatedMethod errorLevel="info" />
<DeprecatedProperty errorLevel="info" />
<DeprecatedClass errorLevel="info" />
<DeprecatedConstant errorLevel="info" />
<DeprecatedFunction errorLevel="info" />
<DeprecatedInterface errorLevel="info" />
<DeprecatedTrait errorLevel="info" />

<InternalMethod errorLevel="info" />
<InternalProperty errorLevel="info" />
<InternalClass errorLevel="info" />

<MissingClosureReturnType errorLevel="info" />
<MissingReturnType errorLevel="info" />
<MissingPropertyType errorLevel="info" />
<InvalidDocblock errorLevel="info" />
<MisplacedRequiredParam errorLevel="info" />

<PropertyNotSetInConstructor errorLevel="info" />
<MissingConstructor errorLevel="info" />
<MissingClosureParamType errorLevel="info" />
<MissingParamType errorLevel="info" />

<RedundantCondition errorLevel="info" />

<DocblockTypeContradiction errorLevel="info" />
<RedundantConditionGivenDocblockType errorLevel="info" />

<UnresolvableInclude errorLevel="info" />

<RawObjectIteration errorLevel="info" />

<InvalidStringClass errorLevel="info" />
</issueHandlers>
</psalm>
2 changes: 2 additions & 0 deletions src/Support/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
/**
* Create a Twine string object.
*
* @param mixed $string A string
*
* @return \PHLAK\Twine\Str
*/
function str($string)
Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Caseable.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function uppercase(string $mode = Config\Uppercase::ALL) : self
);

case Config\Uppercase::WORDS:
$string = preg_replace_callback('/(\p{Ll})[\S]*/u', function ($matched) {
$string = preg_replace_callback('/(\p{Ll})[\S]*/u', function (array $matched) {
return mb_strtoupper($matched[1], $this->encoding) . mb_substr($matched[0], 1, null, $this->encoding);
}, $this->string);

Expand Down Expand Up @@ -81,7 +81,7 @@ public function lowercase(string $mode = Config\Lowercase::ALL) : self
);

case Config\Lowercase::WORDS:
$string = preg_replace_callback('/(\p{Lu})[\S]*/u', function ($matched) {
$string = preg_replace_callback('/(\p{Lu})[\S]*/u', function (array $matched) {
return mb_strtolower($matched[1], $this->encoding) . mb_substr($matched[0], 1, null, $this->encoding);
}, $this->string);

Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Convenience.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function words() : array
{
preg_match_all('/\p{Lu}?[\p{Ll}0-9]+/u', $this->string, $matches);

return array_map(function ($words) {
return array_map(function (string $words) {
return new static($words, $this->encoding);
}, $matches[0]);
}
Expand All @@ -72,7 +72,7 @@ public function words() : array
*
* @return \PHLAK\Twine\Str[]
*/
public function characters($mode = Config\Characters::ALL) : array
public function characters(string $mode = Config\Characters::ALL) : array
{
Config\Characters::validateOption($mode);

Expand Down
4 changes: 2 additions & 2 deletions src/Traits/Encodable.php
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@ public function hex(string $mode = Config\Hex::ENCODE) : self

switch ($mode) {
case Config\Hex::ENCODE:
$string = array_reduce(Support\Str::characters($this->string), function ($str, $char) {
$string = array_reduce(Support\Str::characters($this->string), function (string $str, string $char) {
return $str . '\x' . dechex(mb_ord($char, $this->encoding));
}, '');
break;

case Config\Hex::DECODE:
$string = preg_replace_callback('/\\\\x([0-9A-Fa-f]+)/', function ($matched) {
$string = preg_replace_callback('/\\\\x([0-9A-Fa-f]+)/', function (array $matched) {
return mb_chr(hexdec($matched[1]), $this->encoding);
}, $this->string);
break;
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function matchAll(string $pattern) : array
{
preg_match_all($pattern, $this->string, $matches);

return array_map(function ($match) {
return array_map(function (string $match) {
return new static($match, $this->encoding);
}, $matches[0]);
}
Expand Down
10 changes: 5 additions & 5 deletions src/Traits/Segmentable.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public function after(string $string) : self
*/
public function from(string $string) : self
{
return new static(mb_strstr($this->string, $string, null, $this->encoding), $this->encoding);
return new static(mb_strstr($this->string, $string, false, $this->encoding), $this->encoding);
}

/**
Expand Down Expand Up @@ -96,7 +96,7 @@ public function chunk(int $length) : array
{
preg_match_all("/(?:.|\p{L}|\w){1,{$length}}/u", $this->string, $chunks);

return array_map(function ($chunk) {
return array_map(function (string $chunk) {
return new static($chunk, $this->encoding);
}, $chunks[0]);
}
Expand All @@ -111,10 +111,10 @@ public function chunk(int $length) : array
public function split(int $chunks) : array
{
$length = ceil($this->length() / $chunks);
preg_match_all("/(?:.|\p{L}|\w){1,{$length}}/u", $this->string, $chunks);
preg_match_all("/(?:.|\p{L}|\w){1,{$length}}/u", $this->string, $strings);

return array_map(function ($chunk) {
return array_map(function (string $chunk) {
return new static($chunk, $this->encoding);
}, $chunks[0]);
}, $strings[0]);
}
}

0 comments on commit 277e33e

Please sign in to comment.