ScriptHandler::addPhpCsToPreCommitHook()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 16
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 16
ccs 0
cts 15
cp 0
rs 9.4285
cc 3
eloc 11
nc 3
nop 0
crap 12
1
<?php
2
3
/*
4
 * This file is part of Zenify
5
 * Copyright (c) 2012 Tomas Votruba (http://tomasvotruba.cz)
6
 */
7
8
namespace Zenify\CodingStandard\Composer;
9
10
11
final class ScriptHandler
12
{
13
14
	public static function addPhpCsToPreCommitHook()
15
	{
16
		$originFile = getcwd() . '/.git/hooks/pre-commit';
17
		$templateContent = file_get_contents(__DIR__ . '/templates/git/hooks/pre-commit-phpcs');
18
		if (file_exists($originFile)) {
19
			$originContent = file_get_contents($originFile);
20
			if (strpos($originContent, '# run phpcs') === FALSE) {
21
				$newContent = $originContent . PHP_EOL . PHP_EOL . $templateContent;
22
				file_put_contents($originFile, $newContent);
23
			}
24
25
		} else {
26
			file_put_contents($originFile, $templateContent);
27
		}
28
		chmod($originFile, 0755);
29
	}
30
31
}
32