1 | <?php |
||
20 | class ProxyFactory |
||
21 | { |
||
22 | /** The DocumentManager this factory is bound to. */ |
||
23 | private $dm; |
||
24 | /** Whether to automatically (re)generate proxy classes. */ |
||
25 | private $autoGenerate; |
||
26 | /** The namespace that contains all proxy classes. */ |
||
27 | private $proxyNamespace; |
||
28 | /** The directory that contains all proxy classes. */ |
||
29 | private $proxyDir; |
||
30 | |||
31 | /** |
||
32 | * Initializes a new instance of the <tt>ProxyFactory</tt> class that is |
||
33 | * connected to the given <tt>DocumentManager</tt>. |
||
34 | * |
||
35 | * @param DocumentManager $dm The DocumentManager the new factory works for. |
||
36 | * @param string $proxyDir The directory to use for the proxy classes. It must exist. |
||
37 | * @param string $proxyNs The namespace to use for the proxy classes. |
||
38 | * @param boolean $autoGenerate Whether to automatically generate proxy classes. |
||
39 | * @throws ProxyException |
||
40 | */ |
||
41 | public function __construct(DocumentManager $dm, $proxyDir, $proxyNs, $autoGenerate = false) |
||
54 | |||
55 | /** |
||
56 | * Gets a reference proxy instance for the entity of the given type and identified by |
||
57 | * the given identifier. |
||
58 | * |
||
59 | * @param string $className |
||
60 | * @param mixed $identifier |
||
61 | * @return object |
||
62 | */ |
||
63 | public function getProxy($className, $identifier) |
||
81 | |||
82 | /** |
||
83 | * Generate the Proxy file name |
||
84 | * |
||
85 | * @param string $className |
||
86 | * @param string $baseDir Optional base directory for proxy file name generation. |
||
87 | * If not specified, the directory configured on the Configuration of the |
||
88 | * EntityManager will be used by this factory. |
||
89 | * @return string |
||
90 | */ |
||
91 | private function getProxyFileName($className, $baseDir = null) |
||
97 | |||
98 | /** |
||
99 | * Generates proxy classes for all given classes. |
||
100 | * |
||
101 | * @param array $classes The classes (ClassMetadata instances) for which to generate proxies. |
||
102 | * @param string $toDir The target directory of the proxy classes. If not specified, the |
||
103 | * directory configured on the Configuration of the DocumentManager used |
||
104 | * by this factory is used. |
||
105 | */ |
||
106 | public function generateProxyClasses(array $classes, $toDir = null) |
||
120 | |||
121 | /** |
||
122 | * Generates a proxy class file. |
||
123 | * |
||
124 | * @param $class |
||
125 | * @param $fileName |
||
126 | * @param $template |
||
127 | */ |
||
128 | private function generateProxyClass($class, $fileName, $template) |
||
157 | |||
158 | /** |
||
159 | * Generates the methods of a proxy class. |
||
160 | * |
||
161 | * @param ClassMetadata $class |
||
162 | * @return string The code of the generated methods. |
||
163 | */ |
||
164 | private function generateMethods(ClassMetadata $class) |
||
229 | |||
230 | /** |
||
231 | * Generates the code for the __sleep method for a proxy class. |
||
232 | * |
||
233 | * @param $class |
||
234 | * @return string |
||
235 | */ |
||
236 | private function generateSleep(ClassMetadata $class) |
||
255 | |||
256 | /** Proxy class code template */ |
||
257 | private static $proxyClassTemplate = <<<'PHP' |
||
258 | <?php |
||
259 | |||
260 | namespace <namespace>; |
||
261 | |||
262 | /** |
||
263 | * THIS CLASS WAS GENERATED BY THE DOCTRINE ORM. DO NOT EDIT THIS FILE. |
||
264 | */ |
||
265 | class <proxyClassName> extends \<className> implements \Doctrine\ODM\CouchDB\Proxy\Proxy |
||
266 | { |
||
267 | private $__doctrineDocumentManager__; |
||
268 | private $__doctrineIdentifier__; |
||
269 | public $__isInitialized__ = false; |
||
270 | public function __construct($documentManager, $identifier) |
||
271 | { |
||
272 | $this->__doctrineDocumentManager__ = $documentManager; |
||
273 | $this->__doctrineIdentifier__ = $identifier; |
||
274 | } |
||
275 | public function __load() |
||
276 | { |
||
277 | if (!$this->__isInitialized__ && $this->__doctrineDocumentManager__) { |
||
278 | $this->__isInitialized__ = true; |
||
279 | $this->__doctrineDocumentManager__->refresh($this); |
||
280 | unset($this->__doctrineDocumentManager__, $this->__doctrineIdentifier__); |
||
281 | } |
||
282 | } |
||
283 | |||
284 | public function __isInitialized() |
||
285 | { |
||
286 | return $this->__isInitialized__; |
||
287 | } |
||
288 | |||
289 | <methods> |
||
290 | |||
291 | public function __sleep() |
||
292 | { |
||
293 | <sleepImpl> |
||
294 | } |
||
295 | } |
||
296 | PHP; |
||
297 | } |
||
298 | |||
299 |
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.