Passed
Push — developer ( 2f6199...306ed3 )
by Mariusz
70:42 queued 35:47
created

Api   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 38
Duplicated Lines 23.68 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 2
dl 9
loc 38
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B display() 9 31 7

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
/**
3
 * There are all requests with responses.
4
 *
5
 * @package App
6
 *
7
 * @copyright YetiForce Sp. z o.o.
8
 * @license   YetiForce Public License 3.0 (licenses/LicenseEN.txt or yetiforce.com)
9
 * @author    Tomasz Kur <[email protected]>
10
 * @author    Mariusz Krzaczkowski <[email protected]>
11
 */
12
13
namespace App\Log;
14
15
/**
16
 * Api class.
17
 */
18
class Api extends AbstractBase
0 ignored issues
show
Coding Style introduced by
Api does not seem to conform to the naming convention (Utils?$).

This check examines a number of code elements and verifies that they conform to the given naming conventions.

You can set conventions for local variables, abstract classes, utility classes, constant, properties, methods, parameters, interfaces, classes, exceptions and special methods.

Loading history...
19
{
20
	/** {@inheritdoc} */
21
	protected static $fileName = 'cache' . \DIRECTORY_SEPARATOR . 'logs' . \DIRECTORY_SEPARATOR . 'api.log';
22
23
	/** {@inheritdoc} */
24
	public static function display($value, string $type): string
25
	{
26
		$content = str_repeat('-', 50) . '  ' . $value['request']['date'] . '  ' . str_repeat('-', 50) . PHP_EOL;
27
		$content .= 'Trace: ' . PHP_EOL . print_r(\App\Debug::getBacktrace(), true) . PHP_EOL;
28
		$content .= "Method: [{$value['request']['requestType']}] {$value['request']['method']}\n";
29
		$content .= 'Headers: ' . print_r($value['request']['headers'], true) . PHP_EOL;
30
		if (!empty($value['request']['rawBody'])) {
31
			$content .= "RawBody: \n" . print_r($value['request']['rawBody'], true) . PHP_EOL;
32
		}
33 View Code Duplication
		if (!empty($value['request']['body'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
34
			$content .= 'Body: ' . print_r($value['request']['body'], true) . PHP_EOL . PHP_EOL;
35
		}
36
		$content .= "Status: {$value['response']['status']}\n";
37
		$content .= "Reason phrase: {$value['response']['reasonPhrase']}\n";
38
		$content .= "Time: {$value['response']['time']} sec.\n";
39
		if (!empty($value['response']['error'])) {
40
			$content .= "Error: {$value['response']['error']}\n";
41
		}
42
		$headers = [];
43
		foreach ($value['response']['headers'] as $key => $header) {
44
			$headers[$key] = implode("\n", $header);
45
		}
46
		$content .= 'Headers: ' . print_r($headers, true) . PHP_EOL;
47 View Code Duplication
		if (!empty($value['response']['rawBody'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
48
			$content .= "RawBody: \n" . print_r($value['response']['rawBody'], true) . PHP_EOL;
49
		}
50 View Code Duplication
		if (!empty($value['response']['body'])) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
			$content .= 'Body: ' . print_r($value['response']['body'], true) . PHP_EOL;
52
		}
53
		return $content;
54
	}
55
}
56