Passed
Push — main ( 33d492...e44212 )
by Filipe
12:02
created

JsonMethods::clearTitle()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of Cors
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
declare(strict_types=1);
11
12
namespace Slick\Cors\Infrastructure\Converter;
13
14
use Slick\ErrorHandler\Exception\ExceptionInspector;
15
use Throwable;
16
17
/**
18
 * JsonMethods
19
 *
20
 * @package Slick\Cors\Infrastructure\Converter
21
 */
22
trait JsonMethods
23
{
24
25
    /**
26
     * Clears the title of a Throwable object.
27
     *
28
     * @param Throwable $throwable The Throwable object to extract the title from.
29
     * @return string The cleared title.
30
     */
31
    private function clearTitle(Throwable $throwable): string
32
    {
33
        $parts = explode('\\', get_class($throwable));
34
        $name = array_pop($parts);
35
        return ucfirst(trim(strtolower(implode(' ', preg_split('/(?=[A-Z])/', $name)))));
36
    }
37
38
    /**
39
     * Generates details based on the Throwable object and ExceptionInspector.
40
     *
41
     * @param Throwable $throwable The Throwable object used to retrieve error message.
42
     * @param ExceptionInspector $inspector The ExceptionInspector object to provide additional information.
43
     * @return string The generated details based on the Throwable and ExceptionInspector.
44
     */
45
    private function details(Throwable $throwable, ExceptionInspector $inspector): string
46
    {
47
        $errorMessage = $throwable->getMessage() ? $throwable->getMessage(). " " : null;
48
        return $errorMessage . preg_split('/\r?\n/', ltrim($inspector->help()), 2)[0];
0 ignored issues
show
Bug introduced by
It seems like $inspector->help() can also be of type null; however, parameter $string of ltrim() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

48
        return $errorMessage . preg_split('/\r?\n/', ltrim(/** @scrutinizer ignore-type */ $inspector->help()), 2)[0];
Loading history...
49
    }
50
}
51