Code Coverage
 
Classes and Traits
Functions and Methods
Lines
Total
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
CRAP
40.00% covered (danger)
40.00%
4 / 10
RemoveUnserializeForInternalSerializableClassesPass
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 2
10.40
40.00% covered (danger)
40.00%
4 / 10
 apply
0.00% covered (danger)
0.00%
0 / 1
5.26
57.14% covered (warning)
57.14%
4 / 7
 appendToClass
0.00% covered (danger)
0.00%
0 / 1
2
0.00% covered (danger)
0.00%
0 / 3
<?php
namespace Mockery\Generator\StringManipulation\Pass;
use Mockery\Generator\MockConfiguration;
/**
 * Internal classes can not be instantiated with the newInstanceWithoutArgs 
 * reflection method, so need the serialization hack. If the class also 
 * implements Serializable, we need to replace the standard unserialize method 
 * definition with a dummy
 */
class RemoveUnserializeForInternalSerializableClassesPass 
{
    const DUMMY_METHOD_DEFINITION = 'public function unserialize($string) {} ';
    public function apply($code, MockConfiguration $config)
    {
        $target = $config->getTargetClass();
        if (!$target) {
            return $code;
        }
        if (!$target->hasInternalAncestor() || !$target->implementsInterface("Serializable")) {
            return $code;
        }
        $code = $this->appendToClass($code, self::DUMMY_METHOD_DEFINITION);
        return $code;
    }
    protected function appendToClass($class, $code)
    {
        $lastBrace = strrpos($class, "}");
        $class = substr($class, 0, $lastBrace) . $code . "\n    }\n";
        return $class;
    }
}