Completed
Push — master ( f86360...4e757b )
by Peter
03:09
created

Tabs   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
c 1
b 0
f 0
lcom 0
cbo 0
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C trim() 0 32 7
1
<?php
2
3
/*
4
 * To change this license header, choose License Headers in Project Properties.
5
 * To change this template file, choose Tools | Templates
6
 * and open the template in the editor.
7
 */
8
9
namespace Maslosoft\Zamm\Helpers;
10
11
/**
12
 * Tabs
13
 *
14
 * @author Piotr Maselkowski <pmaselkowski at gmail.com>
15
 */
16
class Tabs
17
{
18
19
	public static function trim(&$lines)
20
	{
21
		$string = false;
22
		if(is_string($lines))
23
		{
24
			$string = true;
25
			$lines = explode(PHP_EOL, $lines);
26
		}
27
		// Trim empty tabs columns
28
		$minTabs = 666;
29
		foreach ($lines as $line)
30
		{
31
			$matches = [];
32
			preg_match("~^\t+~", $line, $matches);
33
			if (!isset($matches[0]))
34
			{
35
				continue;
36
			}
37
			$minTabs = min([$minTabs, strlen($matches[0])]);
38
		}
39
		if ($minTabs < 666)
40
		{
41
			foreach ($lines as &$line)
42
			{
43
				$line = preg_replace("~^\t{{$minTabs}}~", '', $line);
44
			}
45
		}
46
		if($string)
47
		{
48
			$lines = implode(PHP_EOL, $lines);
49
		}
50
	}
51
52
}
53