CodeStyleTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 27
Duplicated Lines 74.07 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 2
dl 20
loc 27
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testConvertToTabs() 10 10 1
A testKeepSpaces() 10 10 1

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
declare(strict_types=1);
4
5
namespace Zenify\DoctrineMigrations\Tests\CodeStyle;
6
7
use PHPUnit\Framework\TestCase;
8
use Zenify\DoctrineMigrations\CodeStyle\CodeStyle;
9
10
11
final class CodeStyleTest extends TestCase
12
{
13
14 View Code Duplication
	public function testConvertToTabs()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
15
	{
16
		$file = sys_get_temp_dir() . '/doctrine-migrations/some-spaced-text-file.txt';
17
		@mkdir(dirname($file));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
18
		file_put_contents($file, '    hi');
19
		(new CodeStyle(CodeStyle::INDENTATION_TABS))->applyForFile($file);
20
21
		$this->assertStringNotEqualsFile($file, '    hi');
22
		$this->assertStringEqualsFile($file, "\thi");
23
	}
24
25
26 View Code Duplication
	public function testKeepSpaces()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in 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...
27
	{
28
		$file = sys_get_temp_dir() . '/doctrine-migrations/some-spaced-text-file.txt';
29
		@mkdir(dirname($file));
0 ignored issues
show
Security Best Practice introduced by
It seems like you do not handle an error condition here. This can introduce security issues, and is generally not recommended.

If you suppress an error, we recommend checking for the error condition explicitly:

// For example instead of
@mkdir($dir);

// Better use
if (@mkdir($dir) === false) {
    throw new \RuntimeException('The directory '.$dir.' could not be created.');
}
Loading history...
30
		file_put_contents($file, '    hi');
31
		(new CodeStyle(CodeStyle::INDENTATION_SPACES))->applyForFile($file);
32
33
		$this->assertStringEqualsFile($file, '    hi');
34
		$this->assertStringNotEqualsFile($file, "\thi");
35
	}
36
37
}
38