master

laravel/framework

Last updated at: 29/12/2023 09:20

EnsureNoPunctuation.php

TLDR

This file, EnsureNoPunctuation.php, is a part of the Demo Projects project. It contains a class named EnsureNoPunctuation in the Illuminate\Console\View\Components\Mutators namespace. The class has a single method called __invoke(), which ensures the given string does not end with punctuation.

Methods

__invoke($string)

This method takes a string as input and ensures that it does not end with punctuation. If the string ends with any of the punctuation marks ".", "?", "!", or ":", it removes the last character and returns the modified string. Otherwise, it returns the original string.

Classes

Class EnsureNoPunctuation

This class is responsible for ensuring that a given string does not end with punctuation. It contains a single method called __invoke(), which performs the necessary checks and modifications on the string.

<?php

namespace Illuminate\Console\View\Components\Mutators;

class EnsureNoPunctuation
{
    /**
     * Ensures the given string does not end with punctuation.
     *
     * @param  string  $string
     * @return string
     */
    public function __invoke($string)
    {
        if (str($string)->endsWith(['.', '?', '!', ':'])) {
            return substr_replace($string, '', -1);
        }

        return $string;
    }
}