EnsurePunctuation.php
TLDR
This file contains a class EnsurePunctuation
that ensures the given string ends with punctuation.
Classes
EnsurePunctuation
This class provides a method __invoke
which takes a string as a parameter and ensures that the string ends with punctuation. If the string does not end with any punctuation marks ('.'
, '?'
, '!'
, ':'
), it appends a period ('.'
) to the string and returns the modified string. If the string already ends with punctuation, it returns the string as is.
<?php
namespace Illuminate\Console\View\Components\Mutators;
class EnsurePunctuation
{
/**
* Ensures the given string ends with punctuation.
*
* @param string $string
* @return string
*/
public function __invoke($string)
{
if (! str($string)->endsWith(['.', '?', '!', ':'])) {
return "$string.";
}
return $string;
}
}