C:\xampp2_not used\php\pear\PHP\CodeCoverage\Report\HTML\Renderer\File.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
<?php
/**
 * PHP_CodeCoverage
 *
 * Copyright (c) 2009-2013, Sebastian Bergmann <sebastian@phpunit.de>.
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 *   * Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   * Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   * Neither the name of Sebastian Bergmann nor the names of his
 *     contributors may be used to endorse or promote products derived
 *     from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 *
 * @category   PHP
 * @package    CodeCoverage
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 * @copyright  2009-2013 Sebastian Bergmann <sebastian@phpunit.de>
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 * @link       http://github.com/sebastianbergmann/php-code-coverage
 * @since      File available since Release 1.1.0
 */

// @codeCoverageIgnoreStart
if (!defined('T_TRAIT')) {
    
define('T_TRAIT'1001);
}

if (!
defined('T_INSTEADOF')) {
    
define('T_INSTEADOF'1002);
}

if (!
defined('T_CALLABLE')) {
    
define('T_CALLABLE'1003);
}
// @codeCoverageIgnoreEnd

/**
 * Renders a PHP_CodeCoverage_Report_Node_File node.
 *
 * @category   PHP
 * @package    CodeCoverage
 * @author     Sebastian Bergmann <sebastian@phpunit.de>
 * @copyright  2009-2013 Sebastian Bergmann <sebastian@phpunit.de>
 * @license    http://www.opensource.org/licenses/BSD-3-Clause  The BSD 3-Clause License
 * @link       http://github.com/sebastianbergmann/php-code-coverage
 * @since      Class available since Release 1.1.0
 */
class PHP_CodeCoverage_Report_HTML_Renderer_File extends PHP_CodeCoverage_Report_HTML_Renderer
{
    
/**
     * @var boolean
     */
    
protected $highlight;

    
/**
     * Constructor.
     *
     * @param string  $templatePath
     * @param string  $charset
     * @param string  $generator
     * @param string  $date
     * @param integer $lowUpperBound
     * @param integer $highLowerBound
     * @param boolean $highlight
     */
    
public function __construct($templatePath$charset$generator$date$lowUpperBound$highLowerBound$highlight)
    {
        
parent::__construct(
          
$templatePath,
          
$charset,
          
$generator,
          
$date,
          
$lowUpperBound,
          
$highLowerBound
        
);

        
$this->highlight $highlight;
    }

    
/**
     * @param PHP_CodeCoverage_Report_Node_File $node
     * @param string                            $file
     */
    
public function render(PHP_CodeCoverage_Report_Node_File $node$file)
    {
        
$template = new Text_Template($this->templatePath 'file.html');

        
$template->setVar(
          array(
            
'items' => $this->renderItems($node),
            
'lines' => $this->renderSource($node)
          )
        );

        
$this->setCommonTemplateVariables($template$node);

        
$template->renderTo($file);
    }

    
/**
     * @param  PHP_CodeCoverage_Report_Node_File $node
     * @return string
     */
    
protected function renderItems(PHP_CodeCoverage_Report_Node_File $node)
    {
        
$template = new Text_Template($this->templatePath 'file_item.html');

        
$methodItemTemplate = new Text_Template(
          
$this->templatePath 'method_item.html'
        
);

        
$items $this->renderItemTemplate(
          
$template,
          array(
            
'name'                         => 'Total',
            
'numClasses'                   => $node->getNumClassesAndTraits(),
            
'numTestedClasses'             => $node->getNumTestedClassesAndTraits(),
            
'numMethods'                   => $node->getNumMethods(),
            
'numTestedMethods'             => $node->getNumTestedMethods(),
            
'linesExecutedPercent'         => $node->getLineExecutedPercent(FALSE),
            
'linesExecutedPercentAsString' => $node->getLineExecutedPercent(),
            
'numExecutedLines'             => $node->getNumExecutedLines(),
            
'numExecutableLines'           => $node->getNumExecutableLines(),
            
'testedMethodsPercent'         => $node->getTestedMethodsPercent(FALSE),
            
'testedMethodsPercentAsString' => $node->getTestedMethodsPercent(),
            
'testedClassesPercent'         => $node->getTestedClassesAndTraitsPercent(FALSE),
            
'testedClassesPercentAsString' => $node->getTestedClassesAndTraitsPercent(),
            
'crap'                         => '<acronym title="Change Risk Anti-Patterns (CRAP) Index">CRAP</acronym>'
          
)
        );

        
$items .= $this->renderFunctionItems(
          
$node->getFunctions(), $methodItemTemplate
        
);

        
$items .= $this->renderTraitOrClassItems(
          
$node->getTraits(), $template$methodItemTemplate
        
);

        
$items .= $this->renderTraitOrClassItems(
          
$node->getClasses(), $template$methodItemTemplate
        
);

        return 
$items;
    }

    
/**
     * @param  array         $items
     * @param  Text_Template $template
     * @return string
     */
    
protected function renderTraitOrClassItems(array $itemsText_Template $templateText_Template $methodItemTemplate)
    {
        if (empty(
$items)) {
            return 
'';
        }

        
$buffer '';

        foreach (
$items as $name => $item) {
            
$numMethods       count($item['methods']);
            
$numTestedMethods 0;

            foreach (
$item['methods'] as $method) {
                if (
$method['executedLines'] == $method['executableLines']) {
                    
$numTestedMethods++;
                }
            }

            
$buffer .= $this->renderItemTemplate(
              
$template,
              array(
                
'name'                         => $name,
                
'numClasses'                   => 1,
                
'numTestedClasses'             => $numTestedMethods == $numMethods 0,
                
'numMethods'                   => $numMethods,
                
'numTestedMethods'             => $numTestedMethods,
                
'linesExecutedPercent'         => PHP_CodeCoverage_Util::percent(
                                                    
$item['executedLines'],
                                                    
$item['executableLines'],
                                                    
FALSE
                                                  
),
                
'linesExecutedPercentAsString' => PHP_CodeCoverage_Util::percent(
                                                    
$item['executedLines'],
                                                    
$item['executableLines'],
                                                    
TRUE
                                                  
),
                
'numExecutedLines'             => $item['executedLines'],
                
'numExecutableLines'           => $item['executableLines'],
                
'testedMethodsPercent'         => PHP_CodeCoverage_Util::percent(
                                                    
$numTestedMethods,
                                                    
$numMethods,
                                                    
FALSE
                                                  
),
                
'testedMethodsPercentAsString' => PHP_CodeCoverage_Util::percent(
                                                    
$numTestedMethods,
                                                    
$numMethods,
                                                    
TRUE
                                                  
),
                
'testedClassesPercent'         => PHP_CodeCoverage_Util::percent(
                                                    
$numTestedMethods == $numMethods 0,
                                                    
1,
                                                    
FALSE
                                                  
),
                
'testedClassesPercentAsString' => PHP_CodeCoverage_Util::percent(
                                                    
$numTestedMethods == $numMethods 0,
                                                    
1,
                                                    
TRUE
                                                  
),
                
'crap'                         => $item['crap']
              )
            );

            foreach (
$item['methods'] as $method) {
                
$buffer .= $this->renderFunctionOrMethodItem(
                  
$methodItemTemplate$method'&nbsp;'
                
);
            }
        }

        return 
$buffer;
    }

    
/**
     * @param  array         $functions
     * @param  Text_Template $template
     * @return string
     */
    
protected function renderFunctionItems(array $functionsText_Template $template)
    {
        if (empty(
$functions)) {
            return 
'';
        }

        
$buffer '';

        foreach (
$functions as $function) {
            
$buffer .= $this->renderFunctionOrMethodItem(
              
$template$function
            
);
        }

        return 
$buffer;
    }

    
/**
     * @param  Text_Template $template
     * @return string
     */
    
protected function renderFunctionOrMethodItem(Text_Template $template, array $item$indent '')
    {
        
$numTestedItems $item['executedLines'] == $item['executableLines'] ? 0;

        return 
$this->renderItemTemplate(
          
$template,
          array(
            
'name'                         => sprintf(
                                                
'%s<a href="#%d">%s</a>',
                                                
$indent,
                                                
$item['startLine'],
                                                
htmlspecialchars($item['signature'])
                                              ),
            
'numMethods'                   => 1,
            
'numTestedMethods'             => $numTestedItems,
            
'linesExecutedPercent'         => PHP_CodeCoverage_Util::percent(
                                                
$item['executedLines'],
                                                
$item['executableLines'],
                                                
FALSE
                                              
),
            
'linesExecutedPercentAsString' => PHP_CodeCoverage_Util::percent(
                                                
$item['executedLines'],
                                                
$item['executableLines'],
                                                
TRUE
                                              
),
            
'numExecutedLines'             => $item['executedLines'],
            
'numExecutableLines'           => $item['executableLines'],
            
'testedMethodsPercent'         => PHP_CodeCoverage_Util::percent(
                                                
$numTestedItems,
                                                
1,
                                                
FALSE
                                              
),
            
'testedMethodsPercentAsString' => PHP_CodeCoverage_Util::percent(
                                                
$numTestedItems,
                                                
1,
                                                
TRUE
                                              
),
            
'crap'                         => $item['crap']
          )
        );
    }

    
/**
     * @param  PHP_CodeCoverage_Report_Node_File $node
     * @return string
     */
    
protected function renderSource(PHP_CodeCoverage_Report_Node_File $node)
    {
        
$coverageData $node->getCoverageData();
        
$ignoredLines $node->getIgnoredLines();
        
$testData     $node->getTestData();
        
$codeLines    $this->loadFile($node->getPath());
        
$lines        '';
        
$i            1;

        foreach (
$codeLines as $line) {
            
$numTests       '';
            
$trClass        '';
            
$popoverContent '';
            
$popoverTitle   '';

            if (!isset(
$ignoredLines[$i]) && isset($coverageData[$i])) {
                
$numTests count($coverageData[$i]);

                if (
$coverageData[$i] === NULL) {
                    
$trClass ' class="warning"';
                }

                else if (
$numTests == 0) {
                    
$trClass ' class="danger"';
                }

                else {
                    
$trClass        ' class="success popin"';
                    
$popoverContent '<ul>';

                    if (
$numTests 1) {
                        
$popoverTitle $numTests ' tests cover line ' $i;
                    } else {
                        
$popoverTitle '1 test covers line ' $i;
                    }

                    foreach (
$coverageData[$i] as $test) {
                        switch (
$testData[$test]) {
                            case 
0: {
                                
$testCSS ' class="success"';
                            }
                            break;

                            case 
1:
                            case 
2: {
                                
$testCSS ' class="warning"';
                            }
                            break;

                            case 
3: {
                                
$testCSS ' class="danger"';
                            }
                            break;

                            case 
4: {
                                
$testCSS ' class="danger"';
                            }
                            break;

                            default: {
                                
$testCSS '';
                            }
                        }

                        
$popoverContent .= sprintf(
                          
'<li%s>%s</li>',

                          
$testCSS,
                          
htmlspecialchars($test)
                        );
                    }

                    
$popoverContent .= '</ul>';
                }
            }

            if (!empty(
$popoverTitle)) {
                
$popover sprintf(
                  
' data-title="%s" data-content="%s" data-placement="bottom" data-html="true"',
                  
$popoverTitle,
                  
htmlspecialchars($popoverContent)
                );
            } else {
                
$popover '';
            }

            
$lines .= sprintf(
              
'     <tr%s%s><td><div align="right"><a name="%d"></a><a href="#%d">%d</a></div></td><td class="codeLine">%s</td></tr>' "\n",
              
$trClass,
              
$popover,
              
$i,
              
$i,
              
$i,
              !
$this->highlight htmlspecialchars($line) : $line
            
);

            
$i++;
        }

        return 
$lines;
    }

    
/**
     * @param  string $file
     * @return array
     */
    
protected function loadFile($file)
    {
        
$buffer file_get_contents($file);
        
$lines  explode("\n"str_replace("\t"'    '$buffer));
        
$result = array();

        if (
count($lines) == 0) {
            return 
$result;
        }

        
$lines array_map('rtrim'$lines);

        if (!
$this->highlight) {
            unset(
$lines[count($lines)-1]);
            return 
$lines;
        }

        
$tokens     token_get_all($buffer);
        
$stringFlag FALSE;
        
$i          0;
        
$result[$i] = '';

        foreach (
$tokens as $j => $token) {
            if (
is_string($token)) {
                if (
$token === '"' && $tokens[$j 1] !== '\\') {
                    
$result[$i] .= sprintf(
                      
'<span class="string">%s</span>',

                      
htmlspecialchars($token)
                    );

                    
$stringFlag = !$stringFlag;
                } else {
                    
$result[$i] .= sprintf(
                      
'<span class="keyword">%s</span>',

                      
htmlspecialchars($token)
                    );
                }

                continue;
            }

            list (
$token$value) = $token;

            
$value str_replace(
              array(
"\t"' '),
              array(
'&nbsp;&nbsp;&nbsp;&nbsp;''&nbsp;'),
              
htmlspecialchars($value)
            );

            if (
$value === "\n") {
                
$result[++$i] = '';
            } else {
                
$lines explode("\n"$value);

                foreach (
$lines as $jj => $line) {
                    
$line trim($line);

                    if (
$line !== '') {
                        if (
$stringFlag) {
                            
$colour 'string';
                        } else {
                            switch (
$token) {
                                case 
T_INLINE_HTML: {
                                    
$colour 'html';
                                }
                                break;

                                case 
T_COMMENT:
                                case 
T_DOC_COMMENT: {
                                    
$colour 'comment';
                                }
                                break;

                                case 
T_ABSTRACT:
                                case 
T_ARRAY:
                                case 
T_AS:
                                case 
T_BREAK:
                                case 
T_CALLABLE:
                                case 
T_CASE:
                                case 
T_CATCH:
                                case 
T_CLASS:
                                case 
T_CLONE:
                                case 
T_CONTINUE:
                                case 
T_DEFAULT:
                                case 
T_ECHO:
                                case 
T_ELSE:
                                case 
T_ELSEIF:
                                case 
T_EMPTY:
                                case 
T_ENDDECLARE:
                                case 
T_ENDFOR:
                                case 
T_ENDFOREACH:
                                case 
T_ENDIF:
                                case 
T_ENDSWITCH:
                                case 
T_ENDWHILE:
                                case 
T_EXIT:
                                case 
T_EXTENDS:
                                case 
T_FINAL:
                                case 
T_FOREACH:
                                case 
T_FUNCTION:
                                case 
T_GLOBAL:
                                case 
T_IF:
                                case 
T_IMPLEMENTS:
                                case 
T_INCLUDE:
                                case 
T_INCLUDE_ONCE:
                                case 
T_INSTANCEOF:
                                case 
T_INSTEADOF:
                                case 
T_INTERFACE:
                                case 
T_ISSET:
                                case 
T_LOGICAL_AND:
                                case 
T_LOGICAL_OR:
                                case 
T_LOGICAL_XOR:
                                case 
T_NAMESPACE:
                                case 
T_NEW:
                                case 
T_PRIVATE:
                                case 
T_PROTECTED:
                                case 
T_PUBLIC:
                                case 
T_REQUIRE:
                                case 
T_REQUIRE_ONCE:
                                case 
T_RETURN:
                                case 
T_STATIC:
                                case 
T_THROW:
                                case 
T_TRAIT:
                                case 
T_TRY:
                                case 
T_UNSET:
                                case 
T_USE:
                                case 
T_VAR:
                                case 
T_WHILE: {
                                    
$colour 'keyword';
                                }
                                break;

                                default: {
                                    
$colour 'default';
                                }
                            }
                        }

                        
$result[$i] .= sprintf(
                          
'<span class="%s">%s</span>',

                          
$colour,
                          
$line
                        
);
                    }

                    if (isset(
$lines[$jj 1])) {
                        
$result[++$i] = '';
                    }
                }
            }
        }

        unset(
$result[count($result)-1]);

        return 
$result;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586