HtmlDataTables::newData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace Ghc\Rosetta\Messages;
4
5
use Ghc\Rosetta\Item;
6
use Ghc\Rosetta\Transformers\DataTable;
7
use Symfony\Component\DomCrawler\Crawler;
8
9
class HtmlDataTables extends Xml
10
{
11
    /**
12
     * Boot Transformer.
13
     */
14 View Code Duplication
    protected function boot()
0 ignored issues
show
Duplication introduced by
This method 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...
15
    {
16
        $this->addDefaultConfig([
17
            'selector'         => 'table',
18
            'hasHeader'        => true,
19
            'useHeaderAsIndex' => true,
20
            'ignoreHeader'     => false,
21
            'orientation'      => 'vertical',
22
        ]);
23
    }
24
25
    /**
26
     * @return string
27
     */
28
    public function newData()
29
    {
30
        return '<html></html>';
31
    }
32
33
    /**
34
     * Get the instance as an array.
35
     *
36
     * @return array
37
     */
38
    public function toArray()
39
    {
40
        $crawler = new Crawler((string) $this->getData());
41
42
        return $crawler->filter($this->getConfig()['selector'])->each(function ($table) {
43
            $rows = [];
0 ignored issues
show
Unused Code introduced by
The assignment to $rows is dead and can be removed.
Loading history...
44
45
            try {
46
                /** @var Crawler $table */
47
                $rows = $table->filter('tr')->each(function ($row) {
48
                    /* @var Crawler $row */
49
                    return $row->filter('th,td')->each(function ($column) {
50
                        /* @var Crawler $column */
51
                        return trim($column->text());
52
                    });
53
                });
54
55
                $rows = (new Item($rows, [new DataTable($this->getConfig())]))->toArray();
56
            } catch (\Exception $e) {
0 ignored issues
show
Coding Style Comprehensibility introduced by
Consider adding a comment why this CATCH block is empty.
Loading history...
57
            }
58
59
            return $rows;
60
        });
61
    }
62
}
63