SuffixTrimmer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 6 2
A __construct() 0 3 1
1
<?php
2
declare(strict_types=1);
3
4
namespace RoadBunch\StringBean;
5
6
7
class SuffixTrimmer extends AbstractFormatter
8
{
9
    public function __construct(
10
        private readonly string $suffix
11
    ) {}
12
13
    public function format(string $subject): string
14
    {
15
        if (str_ends_with($subject, $this->suffix)) {
16
            return rtrim(substr($subject, 0, strlen($subject) - strlen($this->suffix)));
17
        }
18
        return $subject;
19
    }
20
}
21