RemoveDestructorPass::apply()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 14
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 8
cts 8
cp 1
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 7
nc 3
nop 2
crap 3
1
<?php
2
/**
3
 * Mockery
4
 *
5
 * LICENSE
6
 *
7
 * This source file is subject to the new BSD license that is bundled
8
 * with this package in the file LICENSE.txt.
9
 * It is also available through the world-wide-web at this URL:
10
 * http://github.com/padraic/mockery/blob/master/LICENSE
11
 * If you did not receive a copy of the license and are unable to
12
 * obtain it through the world-wide-web, please send an email
13
 * to [email protected] so we can send you a copy immediately.
14
 *
15
 * @category   Mockery
16
 * @package    Mockery
17
 * @copyright  Copyright (c) 2010 Pádraic Brady (http://blog.astrumfutura.com)
18
 * @license    http://github.com/padraic/mockery/blob/master/LICENSE New BSD License
19
 * @author     Boris Avdeev <[email protected]>
20
 */
21
22
namespace Mockery\Generator\StringManipulation\Pass;
23
24
use Mockery\Generator\MockConfiguration;
25
26
/**
27
 * Remove mock's empty destructor if we tend to use original class destructor
28
 */
29
class RemoveDestructorPass
30
{
31 397
    public function apply($code, MockConfiguration $config)
32
    {
33 397
        $target = $config->getTargetClass();
34
35 397
        if (!$target) {
36 28
            return $code;
37
        }
38
39 373
        if (!$config->isMockOriginalDestructor()) {
40 10
            $code = preg_replace('/public function __destruct\(\)\s+\{.*?\}/sm', '', $code);
41 10
        }
42
43 373
        return $code;
44
    }
45
}
46