Contains   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A toString() 4 4 1
A runMatches() 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
namespace Psr7Unitesting\Html;
4
5
use Symfony\Component\DomCrawler\Crawler;
6
use Psr7Unitesting\Utils\KeyValueConstraintTrait;
7
8 View Code Duplication
class Contains extends AbstractConstraint
0 ignored issues
show
Duplication introduced by
This class 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...
9
{
10
    use KeyValueConstraintTrait;
11
12
    public function toString()
13
    {
14
        return sprintf('has at least one element matching with the selector "%s" that contains "%s"', $this->key, $this->expected);
15
    }
16
17
    protected function runMatches(Crawler $html)
18
    {
19
        $texts = $html->filter($this->key)->each(function ($node) {
20
            return trim($node->text());
21
        });
22
23
        return array_filter($texts, function ($value) {
24
            return strpos($value, $this->expected) !== false;
25
        });
26
    }
27
}
28