Completed
Push — master ( df330f...beccd2 )
by Vitaly
02:27
created

Tree::__construct()   B

Complexity

Conditions 1
Paths 1

Size

Total Lines 505
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 2
Metric Value
c 2
b 0
f 2
dl 0
loc 505
rs 8.2857
cc 1
eloc 5
nc 1
nop 0

How to fix   Long Method   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

1
<?php
2
namespace samsonframework\html2less;
3
4
/**
5
 * Created by Vitaly Iegorov <[email protected]>.
6
 * on 15.04.16 at 12:43
7
 */
8
class Tree
9
{
10
    /** @var array Collection of ignored DOM nodes */
11
    public static $ignoredNodes = array(
12
        'head',
13
        'html',
14
        '.clear',
15
        '&.clear',
16
        '.clearfix',
17
        '&.clearfix',
18
        'body',
19
        'meta',
20
        'script',
21
        'link',
22
        'title',
23
        'br'
24
    );
25
26
    public function __construct()
27
    {
28
        $example = <<<'HTML'
29
        <html lang="en"><head>
30
<base href="/">
31
<script type="text/javascript" id="www-widgetapi-script" src="https://s.ytimg.com/yts/jsbin/www-widgetapi-vfl0mFVOk/www-widgetapi.js" async=""></script><script type="text/javascript" async="" src="http://www.google-analytics.com/analytics.js"></script><script src="https://www.youtube.com/iframe_api"></script><script async="" src="//www.googletagmanager.com/gtm.js?id=GTM-WWZ2DS"></script><script type="text/javascript">var __SAMSONPHP_STARTED = new Date().getTime();</script>
32
<!--[if lt IE 9]>
33
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
34
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
35
<![endif]-->
36
        <title>Pray for Ukraine</title>
37
        <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
38
        <meta name="google-site-verification" content="P7vIywlGAp7AXpXBP8mk3Q9s4QG0MSph3IoRzR9Yx4U">
39
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
40
        <!-- Latest 3.2.x goodshare.js minify version from jsDelivr CDN -->
41
        <script src="https://cdn.jsdelivr.net/jquery.goodshare.js/3.2.5/goodshare.min.js"></script>
42
        <link property="stylesheet" href="https://fonts.googleapis.com/css?family=Open+Sans:400,700,700italic,300italic,300,400italic&amp;subset=latin,cyrillic" rel="stylesheet" type="text/css">
43
    <link rel="alternate" lang="uk" href="http://prayforukraine.dev/ua/"><link rel="alternate" lang="ru" href="http://prayforukraine.dev/ru/http://prayforukraine.dev/ua/">
44
<link type="text/css" rel="stylesheet" href="/cache/resourcer/default/bb5d08be43e350c3df6dbd4cd7f81e97.css">
45
</head>
46
47
    <body id="main">
48
        <section class="header">
49
            <h6 hidden="">Header</h6>
50
            <div class="inner-section">
51
                <a class="logo-img" href="http://prayforukraine.dev"></a>
52
                <a class="logo-word" href="http://prayforukraine.dev"></a>
53
54
                <div class="close menu-open"></div>
55
                <nav class="menu">
56
                    <div class="locale">
57
                        <!-- i18n Locale selection block Created by Vitaly Iegorov <[email protected]> on 07.03.14 at 12:03 start -->
58
<div class="i18n-current" style="display: none;">
59
    en</div>
60
<ul class="i18n-list">
61
    <li class="i18n-locale-en i18n-active">
62
    <a href="http://prayforukraine.dev/"></a>
63
</li><li class="i18n-locale-ua ">
64
    <a href="http://prayforukraine.dev/ua/"></a>
65
</li><li class="i18n-locale-ru ">
66
    <a href="http://prayforukraine.dev/ru/"></a>
67
</li></ul>
68
<!-- i18n Locale selection block Created by Vitaly Iegorov <[email protected]> on 07.03.14 at 12:03 end -->                    </div>
69
                    <a class="menu-text" id="projects-link" href="http://prayforukraine.dev/projects/">projects</a>
70
                    <a class="menu-text" id="news-link" href="http://prayforukraine.dev/news/">news</a>
71
                    <a class="menu-text" id="team-link" href="http://prayforukraine.dev/team/">our team</a>
72
                    <div class="button orange open-popup">Donate</div>
73
                </nav>
74
            </div>
75
        </section>
76
77
        <!-- PAGE BLOCK -->
78
<section class="page main-page" style="background-image: url(/view/?p=/src/main/www/img/page.png)">
79
    <h6 class="big-text">
80
        DONATE<br>SAVE LIVES TOGETHER    </h6>
81
    <div class="center">
82
        <div class="button orange scroll-button">
83
            Donate now        </div>
84
    </div>
85
</section>
86
87
<div class="video-color">
88
    <section class="video">
89
        <h6 hidden="">Video</h6>
90
        <div class="image"></div>
91
                    <div class="center">
92
                <div class="center-video-button"></div>
93
                <iframe class="video-youtube" id="YVjPznbAtmA" frameborder="0" allowfullscreen="1" title="YouTube video player" width="638" height="355" src="https://www.youtube.com/embed/YVjPznbAtmA?rel=0&amp;autohide=1&amp;controls=0&amp;showinfo=0&amp;enablejsapi=1&amp;origin=http%3A%2F%2Fprayforukraine.dev"></iframe>
94
            </div>
95
            </section>
96
</div>
97
98
<!-- PROJECTS BLOCK -->
99
у
100
<section class="projects">
101
    <div class="inner-section">
102
        <div class="list-projects">
103
    <div class="swiper-button-prev swiper-button-prev-projects swiper-button-disabled"></div>
104
    <div class="swiper-container swiper-container-horizontal swiper-projects">
105
        <div class="swiper-wrapper">
106
            <div onclick="location.href='http://prayforukraine.dev/projects/projects-29/'" class="one-project swiper-slide swiper-slide-active">
107
    <div class="photo" style="background-image: url('')"></div>
108
    <div class="description">
109
        <div class="title">
110
            Test        </div>
111
        <div class="text">
112
            Test info        </div>
113
    </div>
114
            <div class="center">
115
            <a onclick="location.href='http://prayforukraine.dev/projects/projects-29/'" class="button white">learn more</a>
116
        </div>
117
    </div><div onclick="location.href='http://prayforukraine.dev/projects/portable-medical-equipment/'" class="one-project swiper-slide swiper-slide-next">
118
    <div class="photo" style="background-image: url('/upload/2cc3b934e2015910bc152b10341af8f7.jpg')"></div>
119
    <div class="description">
120
        <div class="title">
121
            PORTABLE MEDICAL EQUIPMENT        </div>
122
        <div class="text">
123
            Pray for Ukraine collects donations to provide necessary items such as military equipment and medicines. Military special forces in the Eastern region of Ukraine continue to carry out its primary duty - to protect especially important sites covering the state border and protect the civilian population.         </div>
124
    </div>
125
            <div class="center">
126
            <a onclick="location.href='http://prayforukraine.dev/projects/portable-medical-equipment/'" class="button white">learn more</a>
127
        </div>
128
    </div><div onclick="location.href='http://prayforukraine.dev/projects/firstaidkit/'" class="one-project swiper-slide">
129
    <div class="photo" style="background-image: url('/upload/5472d2827386fb3a3d834708209390a6.jpeg')"></div>
130
    <div class="description">
131
        <div class="title">
132
            Individual First Aid Kit        </div>
133
        <div class="text">
134
            The Individual First Aid Kit, or IFAK, gives a soldier the ability to administer Self-Aid/Buddy-Aid and provides a path for intervention of two leading causes of death on the battlefield, severe hemorrhaging and blocked airways        </div>
135
    </div>
136
            <div class="center">
137
            <a onclick="location.href='http://prayforukraine.dev/projects/firstaidkit/'" class="button white">learn more</a>
138
        </div>
139
    </div><div onclick="location.href='http://prayforukraine.dev/projects/shelter-chervonoarmiysk/'" class="one-project swiper-slide">
140
    <div class="photo" style="background-image: url('/upload/5c5ebda197c9c53ab9272d33ab5eeb6c.jpg')"></div>
141
    <div class="description">
142
        <div class="title">
143
            Help shelter for child victims of war        </div>
144
        <div class="text">
145
            Shelter Chervonoarmiysk is for 30 children who lost their parents because of the war. A few miles from their destroyed homes        </div>
146
    </div>
147
            <div class="center">
148
            <a onclick="location.href='http://prayforukraine.dev/projects/shelter-chervonoarmiysk/'" class="button white">learn more</a>
149
        </div>
150
    </div><div onclick="location.href='http://prayforukraine.dev/projects/help-disabled-children-veronika/'" class="one-project swiper-slide">
151
    <div class="photo" style="background-image: url('/upload/337a7990213c708c97216461ecfa443a.png')"></div>
152
    <div class="description">
153
        <div class="title">
154
            Help Veronika to live, 3 years, bone marrow cancer        </div>
155
        <div class="text">
156
            Help Veronika to live, 3 years, bone marrow cancer        </div>
157
    </div>
158
            <div class="center">
159
            <a onclick="location.href='http://prayforukraine.dev/projects/help-disabled-children-veronika/'" class="button white">learn more</a>
160
        </div>
161
    </div>        </div>
162
    </div>
163
    <div class="swiper-button-next swiper-button-next-projects"></div>
164
</div>    </div>
165
</section>
166
<!-- TEAM BLOCK -->
167
<section class="team">
168
    <div class="inner-section">
169
        <div class="header-text">Our team</div>
170
        <div class="all-people">
171
    <div class="one">
172
    <a class="photo" href="http://prayforukraine.dev/team/yaroslav-kandyba/" style="background-image: url('/upload/bb3a1d725df000114e85470a2253cddb.png')"></a>
173
    <a class="social" href="https://www.facebook.com/profile.php?id=100011337422732&amp;fref=ts"></a>
174
    <div class="description">
175
        <div class="name">
176
            Yaroslav Kandyba        </div>
177
        <div class="text">
178
            <p>Yaroslav is founder of Pray for Ukraine foundation. He helps children who became victims of war, who lost their parents. From age of 4 to 18 they got serious problems with health, they don't have place where to live, nothing to eat and to wear. Also Yaroslav collects aid for people who needs immediately medical help. Also soldier collects aid for army needs such as warm clothing, uniforms, first aid kits.</p><p></p>        </div>
179
                    <a href="http://prayforukraine.dev/team/yaroslav-kandyba/ " class="more-info">More</a>
180
            </div>
181
</div><div class="one">
182
    <a class="photo" href="http://prayforukraine.dev/team/yurii-bodnar/" style="background-image: url('/upload/99ee88634efc76d33d9e2a1d6c7b802a.jpg')"></a>
183
    <a class="social" href="https://www.facebook.com/profile.php?id=100007071728288&amp;sk=photos"></a>
184
    <div class="description">
185
        <div class="name">
186
            Yurii Bodnar        </div>
187
        <div class="text">
188
189
190
191
192
193
194
195
<p class="p1"><span class="s1" style="font-size: 14px; font-family: Arial;">Yurii has been being volunteer and soldier in Ukraine army for the 2nd year. His dangerous profession became his way of life. Every day Yurii helps to survive his colleagues. He collects aid for the most necessary things military - equipment for the conduct of defense and medical suppliements. </span></p>        </div>
196
                    <a href="http://prayforukraine.dev/team/yurii-bodnar/ " class="more-info">More</a>
197
            </div>
198
</div><div class="one">
199
    <a class="photo" href="http://prayforukraine.dev/team/taras-chmut/" style="background-image: url('/upload/7fdff13b16a629da550c0abd009b0db4.jpg')"></a>
200
    <a class="social" href="https://www.facebook.com/profile.php?id=100003822077764&amp;fref=ts"></a>
201
    <div class="description">
202
        <div class="name">
203
            Taras Chmut        </div>
204
        <div class="text">
205
            Taras is only 24, but he can already proud about himself. He works volunteer and soldier in <span style="font-family: Arial; font-size: 14px;">the Naval Forces of Ukraine. He decided that he could not stay apart when his country is in danger. Taras decided to work in ukrainian navy because there are soldiers who are worth to be like them. Taras knew from childhood that only strong men work in naval forces. besides, there are many problem in ukrainian navy. First of all the lack of equipment for protection against attacks of the occupier. </span>        </div>
206
                    <a href="http://prayforukraine.dev/team/taras-chmut/ " class="more-info">More</a>
207
            </div>
208
</div><div class="one">
209
    <a class="photo" href="http://prayforukraine.dev/team/ihor-fedirko/" style="background-image: url('/upload/4d6604dc9ccf08773582c03df09dc811.jpg')"></a>
210
    <a class="social" href="https://www.facebook.com/igor.fedirko?fref=ts"></a>
211
    <div class="description">
212
        <div class="name">
213
            Ihor Fedirko        </div>
214
        <div class="text">
215
216
217
218
219
220
221
222
<p class="p1"><span style="font-family: Arial;"><span class="s1" style="font-size: 14px;">Ihor works as a volunteer in </span><span class="s2"><span style="font-size: 14px;">3-rd and 8-th individual regiments of the Main Intelligence Directorate of the Ministry of Defence of Ukraine and 73-th and 140-th Centers for Special Purposes. The situation in battalions is extremely dangerous - warm clothes and medicines are running out. Soldiers of groups can not organize a high-quality surveillance of enemy equipment because of lack of modern equipment. Ihor helps his colleagues to collect money to buy all the necessary equipment.</span><span style="font-size: 14px;"> </span></span></span></p>        </div>
223
                    <a href="http://prayforukraine.dev/team/ihor-fedirko/ " class="more-info">More</a>
224
            </div>
225
</div></div>        <div class="header-text last">
226
            OUR CURRENT FUNDRAISING PROJECTS AND APPEALS        </div>
227
    </div>
228
</section>
229
<!-- PROJECTS BLOCK -->
230
<section class="projects all-more">
231
    <div class="inner-section">
232
        <div class="list-projects">
233
    <div class="swiper-button-prev swiper-button-prev-specific swiper-button-disabled"></div>
234
    <div class="swiper-container swiper-container-horizontal swiper-specific">
235
        <div class="swiper-wrapper">
236
            <div onclick="location.href='http://prayforukraine.dev/projects/projects-29/'" class="one-project swiper-slide swiper-slide-active" style="width: 235px;">
237
    <div class="photo" style="background-image: url('')"></div>
238
    <div class="description">
239
        <div class="title">
240
            Test        </div>
241
        <div class="text">
242
            Test info        </div>
243
    </div>
244
    </div><div onclick="location.href='http://prayforukraine.dev/projects/portable-medical-equipment/'" class="one-project swiper-slide swiper-slide-next" style="width: 235px;">
245
    <div class="photo" style="background-image: url('/upload/2cc3b934e2015910bc152b10341af8f7.jpg')"></div>
246
    <div class="description">
247
        <div class="title">
248
            PORTABLE MEDICAL EQUIPMENT        </div>
249
        <div class="text">
250
            Pray for Ukraine collects donations to provide necessary items such as military equipment and medicines. Military special forces in the Eastern region of Ukraine continue to carry out its primary duty - to protect especially important sites covering the state border and protect the civilian population.         </div>
251
    </div>
252
    </div><div onclick="location.href='http://prayforukraine.dev/projects/firstaidkit/'" class="one-project swiper-slide" style="width: 235px;">
253
    <div class="photo" style="background-image: url('/upload/5472d2827386fb3a3d834708209390a6.jpeg')"></div>
254
    <div class="description">
255
        <div class="title">
256
            Individual First Aid Kit        </div>
257
        <div class="text">
258
            The Individual First Aid Kit, or IFAK, gives a soldier the ability to administer Self-Aid/Buddy-Aid and provides a path for intervention of two leading causes of death on the battlefield, severe hemorrhaging and blocked airways        </div>
259
    </div>
260
    </div><div onclick="location.href='http://prayforukraine.dev/projects/shelter-chervonoarmiysk/'" class="one-project swiper-slide" style="width: 235px;">
261
    <div class="photo" style="background-image: url('/upload/5c5ebda197c9c53ab9272d33ab5eeb6c.jpg')"></div>
262
    <div class="description">
263
        <div class="title">
264
            Help shelter for child victims of war        </div>
265
        <div class="text">
266
            Shelter Chervonoarmiysk is for 30 children who lost their parents because of the war. A few miles from their destroyed homes        </div>
267
    </div>
268
    </div><div onclick="location.href='http://prayforukraine.dev/projects/help-disabled-children-veronika/'" class="one-project swiper-slide" style="width: 235px;">
269
    <div class="photo" style="background-image: url('/upload/337a7990213c708c97216461ecfa443a.png')"></div>
270
    <div class="description">
271
        <div class="title">
272
            Help Veronika to live, 3 years, bone marrow cancer        </div>
273
        <div class="text">
274
            Help Veronika to live, 3 years, bone marrow cancer        </div>
275
    </div>
276
    </div>        </div>
277
    </div>
278
    <div class="swiper-button-next swiper-button-next-specific"></div>
279
</div>        <div class="center">
280
            <a class="button white" href="http://prayforukraine.dev/projects/">learn more</a>
281
        </div>
282
    </div>
283
</section>        <!-- FOOTER SECTION -->
284
        <div id="popup-message">
285
    <div class="popup-close"></div>
286
    <div class="text"></div>
287
</div>
288
289
<div id="footer-message">
290
    <div class="popup-close"></div>
291
    <div class="text"></div>
292
</div>
293
294
<section class="footer">
295
    <div class="email-block">
296
        <h6>
297
            TOGETHER WE CAN MAKE A DIFFERENCE        </h6>
298
        <div class="select-phone">
299
    <select class="select">
300
        <option value="1">$1</option>
301
        <option value="5">$5</option>
302
        <!--        <option value="10">$10</option>-->
303
        <option value="20">$20</option>
304
        <option value="50">$50</option>
305
        <option value="100">$100</option>
306
        <option value="500">$500</option>
307
    </select>
308
</div>
309
<div class="select-money">
310
    <div class="one active" data-value="1">$1</div>
311
    <div class="one" data-value="5">$5</div>
312
    <!--    <div class="one" data-value="10">$10</div>-->
313
    <div class="one" data-value="20">$20</div>
314
    <div class="one" data-value="50">$50</div>
315
    <div class="one" data-value="100">$100</div>
316
    <div class="one" data-value="500">$500</div>
317
</div>        <input type="text" id="footer-input" placeholder="Or enter donation value">
318
        <div class="over-payment">
319
            <div class="info-payment">
320
321
                <div class="info-donator">
322
                    <input type="email" class="gray donator-input" id="footer-donator-email-input" name="email-donator" placeholder="Input your e-mail"><br>
323
                    <input type="text" class="gray donator-input" id="footer-donator-input" name="name-donator" placeholder="Input your name">
324
                </div>
325
326
                <!--                <div class="payment-header">-->
327
                <!--</div>-->
328
                <div class="lists-bank">
329
                    <div class="phone swiper-button-prev swiper-button-prev-footer"></div>
330
                    <div class="swiper-container swiper-footer">
331
                        <div class="swiper-wrapper">
332
    <div class="one">
333
    <!--    <div class="up-bank hidden"></div>-->
334
    <div class="lightpay"></div>
335
</div></div>                    </div>
336
                    <div class="phone swiper-button-next swiper-button-next-footer"></div>
337
                </div>
338
            </div>
339
        </div>
340
341
        <div class="buttons">
342
            <div class="button blue">single donation</div>
343
            <div class="button">give monthly</div>
344
        </div>
345
346
        <div class="share-hidden">
347
            <div class="share">
348
                <div class="share-header">
349
                    Share with your friends                </div>
350
351
                <div class="all-share">
352
                    <a class="goodshare one-share fb" data-type="fb" href="#"></a>
353
                    <a class="goodshare one-share tw" data-type="tw" href="#"></a>
354
                    <a class="goodshare one-share gp" data-type="gp" href="#"></a>
355
                </div>
356
            </div>
357
        </div>
358
    </div>
359
360
    <div class="info-block">
361
        <h5 class="info-header">
362
            HELP US TO SAVE UKRAINIAN LIVES        </h5>
363
        <div class="under-header">
364
            why Ukraine?        </div>
365
366
        <div class="inner-section">
367
    <div class="informations">
368
        <div class="one-info">
369
    <div class="numbers">
370
        18 000    </div>
371
    <div class="description">
372
        <p>people have died</p><p> in undeclared war</p>    </div>
373
</div>
374
&nbsp;<div class="one-info">
375
    <div class="numbers">
376
        1 200    </div>
377
    <div class="description">
378
        <p>among them</p><p>children</p>    </div>
379
</div>
380
&nbsp;<div class="one-info">
381
    <div class="numbers">
382
        30 290    </div>
383
    <div class="description">
384
        <div>injured and</div><div>hospitalized</div>    </div>
385
</div>
386
&nbsp;<div class="one-info">
387
    <div class="numbers">
388
        118 000    </div>
389
    <div class="description">
390
        <div>Children left</div><div>orphans and</div><div>disabled</div>    </div>
391
</div>
392
&nbsp;<div class="one-info">
393
    <div class="numbers">
394
        2 638 000    </div>
395
    <div class="description">
396
        <p>people were forced</p><p> to leave </p><p>their homes<br></p>    </div>
397
</div>
398
&nbsp;    </div>
399
</div>
400
        <div class="big-text">
401
            TOGETHER WE CAN MAKE A DIFFERENCE        </div>
402
403
        <div class="button orange scroll-button">
404
            Donate now        </div>
405
406
        <div class="share">
407
            <div class="share-header">
408
                Share with your friends            </div>
409
            <div class="all-share">
410
                <a class="one-share fb" href="https://www.facebook.com/prayforukraine.org.ua"></a>
411
                <a class="one-share tw" href="https://twitter.com/"></a>
412
                <a class="one-share gp" href="https://plus.google.com/"></a>
413
            </div>
414
        </div>
415
    </div>
416
</section>
417
        <!-- POPUP SECTION -->
418
        <div class="all-page"></div>
419
420
<section class="popup" id="popup">
421
    <h6 hidden="">Popup</h6>
422
    <div class="email-block">
423
424
        <div class="popup-header">
425
            DONATE            <div class="close-popup"></div>
426
        </div>
427
428
        <div class="select-phone">
429
    <select class="select">
430
        <option value="1">$1</option>
431
        <option value="5">$5</option>
432
        <!--        <option value="10">$10</option>-->
433
        <option value="20">$20</option>
434
        <option value="50">$50</option>
435
        <option value="100">$100</option>
436
        <option value="500">$500</option>
437
    </select>
438
</div>
439
<div class="select-money">
440
    <div class="one active" data-value="1">$1</div>
441
    <div class="one" data-value="5">$5</div>
442
    <!--    <div class="one" data-value="10">$10</div>-->
443
    <div class="one" data-value="20">$20</div>
444
    <div class="one" data-value="50">$50</div>
445
    <div class="one" data-value="100">$100</div>
446
    <div class="one" data-value="500">$500</div>
447
</div>
448
        <input type="text" id="popup-input" placeholder="Or enter donation value">
449
450
        <div class="over-payment">
451
            <div class="info-payment">
452
453
                <div class="info-donator">
454
                    <input type="email" class="gray donator-input" id="popup-donator-email-input" name="email-donator" placeholder="Input your e-mail"><br>
455
                    <input type="text" class="gray donator-input" id="popup-donator-input" placeholder="Input your name" name="name-donator">
456
                </div>
457
458
                <!--                <div class="payment-header">-->
459
                <!--</div>-->
460
                <div class="lists-bank">
461
                    <div class="phone swiper-button-prev swiper-button-prev-popup"></div>
462
                    <div class="swiper-container swiper-popup">
463
                        <div class="swiper-wrapper">
464
    <div class="one">
465
    <!--    <div class="up-bank hidden"></div>-->
466
    <div class="lightpay"></div>
467
</div></div>                    </div>
468
                    <div class="phone swiper-button-next swiper-button-next-popup"></div>
469
                </div>
470
            </div>
471
        </div>
472
473
        <div class="buttons">
474
            <div class="button blue">single donation</div>
475
            <div class="button">give monthly</div>
476
        </div>
477
478
        <div class="share-hidden">
479
            <div class="popup-thanks"></div>
480
            <div class="share">
481
                <div class="share-header">
482
                    Share with your friends                </div>
483
484
                <div class="all-share">
485
                    <a class="goodshare one-share fb" data-type="fb" href="#"></a>
486
                    <a class="goodshare one-share tw" data-type="tw" href="#"></a>
487
                    <a class="goodshare one-share gp" data-type="gp" href="#"></a>
488
                </div>
489
            </div>
490
        </div>
491
    </div>
492
</section>
493
        <section class="popup" id="popup-thanks-payment">
494
            <div class="email-block">
495
                <div class="popup-header">
496
                    Thank you for your donation!
497
                    <div class="close-popup"></div>
498
                </div>
499
500
                <div class="share-hidden" style="display: block;">
501
                    <div class="share">
502
                        <div class="share-header">
503
                            Share with your friends
504
                        </div>
505
                        <div class="all-share">
506
                            <a class="goodshare one-share fb" data-type="fb" href="#"></a>
507
                            <a class="goodshare one-share tw" data-type="tw" href="#"></a>
508
                            <a class="goodshare one-share gp" data-type="gp" href="#"></a>
509
                        </div>
510
                    </div>
511
                </div>
512
            </div>
513
        </section>
514
515
        <!-- Google Tag Manager -->
516
        <noscript>&lt;iframe src="//www.googletagmanager.com/ns.html?id=GTM-WWZ2DS"
517
                          height="0" width="0" style="display:none;visibility:hidden"&gt;&lt;/iframe&gt;</noscript>
518
        <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start':
519
                new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0],
520
                j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src=
521
                '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f);
522
            })(window,document,'script','dataLayer','GTM-WWZ2DS');</script>
523
        <!-- End Google Tag Manager -->
524
525
<script type="text/javascript" src="/cache/resourcer/default/52f7a218fc1ffe5f12080fd5a664c7f5.js"></script><div class="__loader_bg" style="display: none;"><div class="__loader_middle"><div id="canvas-loader_2170" class="__loader_canvas"><div id="canvasLoader" style="display: block;"><canvas width="72" height="72"></canvas><canvas width="72" height="72" style="display: none;"></canvas></div></div><div class="text"></div></div></div>
526
527
</body></html>
528
HTML;
529
        $this->build($example);
530
    }
531
532
    /**
533
     * Build destination code tree from source code.
534
     *
535
     * @param string $source Source code
536
     */
537
    public function build($source)
538
    {
539
        // Prepare source code
540
        $source = $this->prepare($source);
541
542
        // Build destination node tree
543
        $tree = $this->analyze($source);
544
545
        trace($tree);
546
    }
547
548
    /**
549
     * Source code cleaner.
550
     *
551
     * @param string $source
552
     *
553
     * @return string Cleared source code
554
     */
555
    protected function prepare($source)
556
    {
557
        // Remove all PHP code from view
558
        return trim(preg_replace('/<\?(php|=).*?\?>/', '', $source));
559
    }
560
561
    /**
562
     * Analyze source code and create destination code tree.
563
     *
564
     * @param string $source Source code
565
     *
566
     * @return HTMLDOMNode Internal code tree
567
     */
568
    protected function &analyze($source)
569
    {
570
        libxml_use_internal_errors(true);
571
572
        /** @var \DOMNode Pointer to current dom element */
573
        $dom = new \DOMDocument();
574
        $dom->loadHTML($source);
575
576
        // Perform recursive node analysis
577
        return $this->analyzeSourceNode($dom, new HTMLDOMNode(new \DOMNode()));
578
    }
579
580
    /**
581
     * Perform source node analysis.
582
     *
583
     * @param \DOMNode    $domNode
584
     * @param HTMLDOMNode $parent
585
     *
586
     * @return HTMLDOMNode
587
     */
588
    protected function &analyzeSourceNode(\DOMNode $domNode, HTMLDOMNode $parent)
589
    {
590
        /** @var \DOMNode[] $children */
591
        $children = [];
592
        /** @var array $tags tag name => count collection */
593
        $tags = [];
594
595
        // Work only with DOMElements
596
        foreach ($domNode->childNodes as $child) {
597
            if ($child->nodeType === 1) {
598
                $children[] = $child;
599
600
                // Get child node tag and count them
601
                $tag = $child->nodeName;
602
                if (!array_key_exists($tag, $tags)) {
603
                    $tags[$tag] = 1;
604
                } else {
605
                    $tags[$tag]++;
606
                }
607
            }
608
        }
609
610
        // Iterate all normal DOM nodes
611
        foreach ($children as $child) {
612
            // Create internal node instance
613
            $node = new HTMLDOMNode($child, $parent);
0 ignored issues
show
Documentation introduced by
$parent is of type object<samsonframework\html2less\HTMLDOMNode>, but the function expects a null|object<self>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
614
615
            // Go deeper in recursion
616
            $this->analyzeSourceNode($child, $node);
617
        }
618
619
        return $parent;
620
    }
621
622
    /**
623
     * Handle current DOM node and transform it to LESS node
624
     *
625
     * @param \DOMNode $node Pointer to current analyzed DOM node
626
     * @param array    $path
627
     *
628
     * @internal param \samsonos\php\skeleton\Node $parent Pointer to parent LESS Node
629
     */
630
    protected function handleNode(\DOMNode & $node, &$path = array())
631
    {
632
        // Collect normal HTML DOM nodes
633
        /** @var \DOMNode[] $children */
634
        $children = array();
635
        foreach ($node->childNodes as $child) {
636
            // Work only with DOMElements
637
            if ($child->nodeType == 1) {
638
                $children[] = $child;
639
            }
640
        }
641
        // Group current level HTML DOM nodes by tag name and count them
642
        $childrenTagArray = array();
643
        foreach ($children as $child) {
644
            $tag = $child->nodeName;
645
            if (!isset($childrenTagArray[$tag])) {
646
                $childrenTagArray[$tag] = 1;
647
            } else $childrenTagArray[$tag]++;
0 ignored issues
show
Coding Style Best Practice introduced by
It is generally a best practice to always use braces with control structures.

Adding braces to control structures avoids accidental mistakes as your code changes:

// Without braces (not recommended)
if (true)
    doSomething();

// Recommended
if (true) {
    doSomething();
}
Loading history...
648
        }
649
        // Iterate all normal DOM nodes
650
        foreach ($children as $child) {
651
            // Create LESS node
652
            $childNode = new HTMLDOMNode($child);
653
            // If this LESS node has NO CSS classes
654
            if (sizeof($childNode->class) == 0) {
655
                // Create new multidimensional array key group
656
                if (!isset($path[$child->nodeName])) {
657
                    $path[$child->nodeName] = array();
658
                }
659
                // Go deeper in recursion with current child node and new path
660
                $this->handleNode($child, $path[$child->nodeName]);
661
            } else { // This child DOM node has CSS classes
662
                // Get first node class and remove it from array og classes
663
                $firstClass = array_shift($childNode->class);
664
                // Save current LESS path
665
                $oldPath = &$path;
666
                // If there is more than one DOM child node with this tag name at this level
667
                if ($childrenTagArray[$childNode->tag] > 1 && $childNode->tag != 'div') {
668
                    // Create correct LESS class name
669
                    $class = '&.' . $firstClass;
670
                    // Create new multidimensional array key group with tag name group
671
                    if (!isset($path[$child->nodeName][$class])) {
672
                        $path[$child->nodeName][$class] = array();
673
                    }
674
                    // Go deeper in recursion with current child node and new path with tag name group and CSS class name group
675
                    $this->handleNode($child, $path[$child->nodeName][$class]);
676
                    // Make new path as current
677
                    $path = &$path[$child->nodeName][$class];
678
                } else { // There is only on child with this tag name at this level
679
                    // Create correct LESS class name
680
                    $class = '.' . $firstClass;
681
                    // Create new multidimensional array key group without tag name group
682
                    if (!isset($path[$class])) {
683
                        $path[$class] = array();
684
                    }
685
                    // Go deeper in recursion with current child node and new path with CSS class name group
686
                    $this->handleNode($child, $path[$class]);
687
                    // Make new path as current
688
                    $path = &$path[$class];
689
                }
690
                // Iterate all other classes starting from second class
691
                foreach ($childNode->class as $class) {
692
                    // Create correct LESS class name
693
                    $class = '&.' . $class;
694
                    // Create new multidimensional array key group with tag name group
695
                    if (!isset($path[$class])) {
696
                        $path[$class] = array();
697
                    }
698
                    // Go deeper in recursion with current child node and new path with tag name group and CSS class name group
699
                    $this->handleNode($child, $path[$class]);
700
                }
701
                // Return old LESS path tree
702
                $path = &$oldPath;
703
            }
704
        }
705
    }
706
}
707