Nesting   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
c 0
b 0
f 0
lcom 0
cbo 0
dl 0
loc 27
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
C solution() 0 24 7
1
<?php
2
3
namespace Lesson05;
4
5
class Nesting
6
{
7
    public function solution($S)
8
    {
9
        $length = strlen($S);
10
        if ($length) {
11
            $parentheses = [];
12
            for ($i = 0; $i < $length; $i++) {
13
                if ($S[$i] == '(') {
14
                    array_push($parentheses, '(');
15
                } elseif ($S[$i] == ')') {
16
                    if (empty($parentheses)) {
17
                        return 0;
18
                    }
19
                    array_pop($parentheses);
20
                }
21
            }
22
            if (empty($parentheses)) {
23
                return 1;
24
            } else {
25
                return 0;
26
            }
27
        }
28
29
        return 1;
30
    }
31
}
32