CodeStyle   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 41
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A applyForFile() 0 6 2
A convertSpacesToTabsForFile() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Zenify
7
 * Copyright (c) 2014 Tomas Votruba (http://tomasvotruba.cz)
8
 */
9
10
namespace Zenify\DoctrineMigrations\CodeStyle;
11
12
use Zenify\DoctrineMigrations\Contract\CodeStyle\CodeStyleInterface;
13
14
15
final class CodeStyle implements CodeStyleInterface
16
{
17
18
	/**
19
	 * @var string
20
	 */
21
	const INDENTATION_TABS = 'tabs';
22
23
	/**
24
	 * @var string
25
	 */
26
	const INDENTATION_SPACES = 'spaces';
27
28
	/**
29
	 * @var string
30
	 */
31
	private $indentationStandard;
32
33
34
	public function __construct(string $indentationStandard)
35 8
	{
36
		$this->indentationStandard = $indentationStandard;
37 8
	}
38 8
39
40
	public function applyForFile(string $file)
41
	{
42
		if ($this->indentationStandard === self::INDENTATION_TABS) {
43
			$this->convertSpacesToTabsForFile($file);
44 4
		}
45
	}
46 4
47 3
48
	private function convertSpacesToTabsForFile(string $file)
49 4
	{
50
		$code = file_get_contents($file);
51
		$code = preg_replace('/ {4}/', "\t", $code);
52
		file_put_contents($file, $code);
53
	}
54
55
}
56