1 | <?php |
||
19 | class ProxyFactory |
||
20 | { |
||
21 | /** The DocumentManager this factory is bound to. */ |
||
22 | private $dm; |
||
23 | /** Whether to automatically (re)generate proxy classes. */ |
||
24 | private $autoGenerate; |
||
25 | /** The namespace that contains all proxy classes. */ |
||
26 | private $proxyNamespace; |
||
27 | /** The directory that contains all proxy classes. */ |
||
28 | private $proxyDir; |
||
29 | |||
30 | /** |
||
31 | * Initializes a new instance of the <tt>ProxyFactory</tt> class that is |
||
32 | * connected to the given <tt>DocumentManager</tt>. |
||
33 | * |
||
34 | * @param DocumentManager $dm The DocumentManager the new factory works for. |
||
35 | * @param string $proxyDir The directory to use for the proxy classes. It must exist. |
||
36 | * @param string $proxyNs The namespace to use for the proxy classes. |
||
37 | * @param boolean $autoGenerate Whether to automatically generate proxy classes. |
||
38 | * @throws ProxyException |
||
39 | */ |
||
40 | public function __construct(DocumentManager $dm, $proxyDir, $proxyNs, $autoGenerate = false) |
||
53 | |||
54 | /** |
||
55 | * Gets a reference proxy instance for the entity of the given type and identified by |
||
56 | * the given identifier. |
||
57 | * |
||
58 | * @param string $className |
||
59 | * @param mixed $identifier |
||
60 | * @return object |
||
61 | */ |
||
62 | public function getProxy($className, $identifier) |
||
80 | |||
81 | /** |
||
82 | * Generate the Proxy file name |
||
83 | * |
||
84 | * @param string $className |
||
85 | * @param string $baseDir Optional base directory for proxy file name generation. |
||
86 | * If not specified, the directory configured on the Configuration of the |
||
87 | * EntityManager will be used by this factory. |
||
88 | * @return string |
||
89 | */ |
||
90 | private function getProxyFileName($className, $baseDir = null) |
||
96 | |||
97 | /** |
||
98 | * Generates proxy classes for all given classes. |
||
99 | * |
||
100 | * @param array $classes The classes (ClassMetadata instances) for which to generate proxies. |
||
101 | * @param string $toDir The target directory of the proxy classes. If not specified, the |
||
102 | * directory configured on the Configuration of the DocumentManager used |
||
103 | * by this factory is used. |
||
104 | */ |
||
105 | public function generateProxyClasses(array $classes, $toDir = null) |
||
119 | |||
120 | /** |
||
121 | * Generates a proxy class file. |
||
122 | * |
||
123 | * @param $class |
||
124 | * @param $fileName |
||
125 | * @param $template |
||
126 | */ |
||
127 | private function generateProxyClass($class, $fileName, $template) |
||
156 | |||
157 | /** |
||
158 | * Generates the methods of a proxy class. |
||
159 | * |
||
160 | * @param ClassMetadata $class |
||
161 | * @return string The code of the generated methods. |
||
162 | */ |
||
163 | private function generateMethods(ClassMetadata $class) |
||
219 | |||
220 | /** |
||
221 | * Generates the code for the __sleep method for a proxy class. |
||
222 | * |
||
223 | * @param $class |
||
224 | * @return string |
||
225 | */ |
||
226 | private function generateSleep(ClassMetadata $class) |
||
245 | |||
246 | /** Proxy class code template */ |
||
247 | private static $proxyClassTemplate = <<<'PHP' |
||
248 | <?php |
||
249 | |||
250 | namespace <namespace>; |
||
251 | |||
252 | /** |
||
253 | * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. |
||
254 | */ |
||
255 | class <proxyClassName> extends \<className> implements \Doctrine\ODM\CouchDB\Proxy\Proxy |
||
256 | { |
||
257 | private $__doctrineDocumentManager__; |
||
258 | private $__doctrineIdentifier__; |
||
259 | public $__isInitialized__ = false; |
||
260 | public function __construct($documentManager, $identifier) |
||
261 | { |
||
262 | $this->__doctrineDocumentManager__ = $documentManager; |
||
263 | $this->__doctrineIdentifier__ = $identifier; |
||
264 | } |
||
265 | public function __load() |
||
266 | { |
||
267 | if (!$this->__isInitialized__ && $this->__doctrineDocumentManager__) { |
||
268 | $this->__isInitialized__ = true; |
||
269 | $this->__doctrineDocumentManager__->refresh($this); |
||
270 | unset($this->__doctrineDocumentManager__, $this->__doctrineIdentifier__); |
||
271 | } |
||
272 | } |
||
273 | |||
274 | public function __isInitialized() |
||
275 | { |
||
276 | return $this->__isInitialized__; |
||
277 | } |
||
278 | |||
279 | <methods> |
||
280 | |||
281 | public function __sleep() |
||
282 | { |
||
283 | <sleepImpl> |
||
284 | } |
||
285 | } |
||
286 | PHP; |
||
287 | } |
||
288 | |||
289 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.