for testing and deploying your application
for finding and fixing issues
for empowering human code reviews
<?php
namespace Subreality\Dilmun\Anshar\Utils;
class StringHelper
{
protected $string;
/**
* StringHelper constructor. Accepts and stores a string.
*
* @throws \InvalidArgumentException if not initialized with a string
* @param string $string The string needing help
*/
public function __construct($string)
if (!is_string($string)) {
throw new \InvalidArgumentException("Supplied string is not a string");
}
$this->string = $string;
* Given a delimited string, returns a copy of the string with chunks defined by the delimiter affected by a given
* function.
* @param callable $function The function to be called against the delimited chunks
* @param string[] $delimiters One or more strings delimiting the chunks
$delimiters
string[][]
This check looks for @param annotations where the type inferred by our type inference engine differs from the declared type.
@param
It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.
* @return string A delimited string with chunks affected by the supplied function
public function affectChunks(callable $function, ...$delimiters)
$delimiter_string = "";
$replace_callback = function ($matches) use ($function) {
$callback_string = $function($matches[0]);
return $callback_string;
};
foreach ($delimiters as $delimiter) {
$delimiter_string .= preg_quote($delimiter, "/");
$pattern = "/[^{$delimiter_string}]+/";
$affected_string = preg_replace_callback($pattern, $replace_callback, $this->string);
return $affected_string;
This check looks for
@paramannotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.