FormData   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 29
ccs 9
cts 9
cp 1
rs 10
c 1
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A format() 0 5 1
A combineErrorMessages() 0 8 2
1
<?php
2
namespace phpbu\App\Log\ResultFormatter;
3
4
use phpbu\App\Log\ResultFormatter;
5
use phpbu\App\Result;
6
7
/**
8
 * FormData ResultFormatter
9
 *
10
 * @package    phpbu
11
 * @subpackage Log
12
 * @author     Sebastian Feldmann <[email protected]>
13
 * @copyright  Sebastian Feldmann <[email protected]>
14
 * @license    https://opensource.org/licenses/MIT The MIT License (MIT)
15
 * @link       https://phpbu.de/
16
 * @since      Class available since Release 5.0.0
17
 */
18
class FormData extends Abstraction implements ResultFormatter
19
{
20
    /**
21
     * Create request body from phpbu result data.
22
     *
23
     * @param  \phpbu\App\Result $result
24
     * @return string
25
     */
26 3
    public function format(Result $result): string
27
    {
28 3
        $body = $this->getSummaryData($result);
29 3
        $body['errorMessages'] = $this->combineErrorMessages($result->getErrors());
30 3
        return http_build_query($body);
31
    }
32
33
    /**
34
     * Combine all error messages.
35
     *
36
     * @param  array $errors
37
     * @return string
38
     */
39 3
    private function combineErrorMessages(array $errors) : string
40
    {
41 3
        $messages = [];
42
        /** @var \Exception $e */
43 3
        foreach ($errors as $e) {
44 3
            $messages[] = $e->getMessage() . ' in file:' . $e->getFile() . ' at line' . $e->getLine();
45
        }
46 3
        return implode(';', $messages);
47
    }
48
}
49