Passed
Push — feature/0.7.0 ( 54b1aa...9c1bf9 )
by Ryuichi
44:30
created

CoreExecuteDelegator::getInstance()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace WebStream\Delegate;
3
4
use WebStream\Core\CoreInterface;
5
use WebStream\Core\CoreController;
6
use WebStream\Core\CoreService;
7
use WebStream\Core\CoreModel;
8
use WebStream\Core\CoreView;
9
use WebStream\Core\CoreHelper;
10
use WebStream\Cache\Driver\CacheDriverFactory;
11
use WebStream\Container\Container;
12
use WebStream\Annotation\Attributes\Filter;
13
use WebStream\Annotation\Attributes\Header;
14
use WebStream\Annotation\Attributes\Template;
15
use WebStream\Exception\ApplicationException;
16
use WebStream\Exception\SystemException;
17
use WebStream\Exception\DelegateException;
18
use WebStream\Exception\Extend\AnnotationException;
19
use WebStream\Exception\Extend\MethodNotFoundException;
20
use WebStream\Util\CommonUtils;
21
use Doctrine\Common\Annotations\AnnotationException as DoctrineAnnotationException;
0 ignored issues
show
Bug introduced by
The type Doctrine\Common\Annotations\AnnotationException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
/**
24
 * CoreExecuteDelegator
25
 * @author Ryuichi TANAKA.
26
 * @since 2015/02/25
27
 * @version 0.4
28
 */
29
class CoreExecuteDelegator
30
{
31
    use CommonUtils;
32
33
    /**
34
     * @var CoreInterface インスタンス
35
     */
36
    private $instance;
37
38
    /**
39
     * @var CoreInterface 注入済みインスタンス
40
     */
41
    private $injectedInstance;
42
43
    /**
44
     * @var Container 依存コンテナ
45
     */
46
    private $container;
47
48
    /**
49
     * @var Logger ロガー
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\Logger was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
50
     */
51
    private $logger;
52
53
    /**
54
     * @var AnnotationContainer アノテーション
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\AnnotationContainer was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
55
     */
56
    private $annotation;
57
58
    /**
59
     * @var array<AnnotationContainer> 例外ハンドラリスト
60
     */
61
    private $exceptionHandler;
62
63
    /**
64
     * constructor
65
     */
66
    public function __construct(CoreInterface $instance, Container $container)
67
    {
68
        $this->instance = $instance;
69
        $this->container = $container;
70
        $this->logger = $container->logger;
0 ignored issues
show
Bug Best Practice introduced by
The property logger does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
Documentation Bug introduced by
It seems like $container->logger can also be of type string. However, the property $logger is declared as type WebStream\Delegate\Logger. Maybe add an additional type check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.

For example, imagine you have a variable $accountId that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to the id property of an instance of the Account class. This class holds a proper account, so the id value must no longer be false.

Either this assignment is in error or a type check should be added for that assignment.

class Id
{
    public $id;

    public function __construct($id)
    {
        $this->id = $id;
    }

}

class Account
{
    /** @var  Id $id */
    public $id;
}

$account_id = false;

if (starsAreRight()) {
    $account_id = new Id(42);
}

$account = new Account();
if ($account instanceof Id)
{
    $account->id = $account_id;
}
Loading history...
71
    }
72
73
    /**
74
     * method missing
75
     */
76
    public function __call($method, $arguments)
77
    {
78
        return $this->run($method, $arguments);
79
    }
80
81
    /**
82
     * overload getter
83
     */
84
    public function __get($name)
85
    {
86
        return $this->getInstance()->{$name};
87
    }
88
89
    /**
90
     * 処理を実行する
91
     * @param string メソッド名
92
     * @param array 引数リスト
93
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment メソッド名 at position 0 could not be parsed: Unknown type name 'メソッド名' at position 0 in メソッド名.
Loading history...
94
    public function run($method, $arguments = [])
95
    {
96
        // すでに注入済みのインスタンスの場合、そのまま実行
97
        if ($this->injectedInstance !== null) {
98
            return $this->execute($method, $arguments);
99
        }
100
101
        try {
102
            $result = null;
103
            if ($this->instance instanceof CoreController) {
104
                $this->controllerInjector($this->getOriginMethod($method), $arguments);
105
            } elseif ($this->instance instanceof CoreService) {
106
                $result = $this->serviceInjector($this->getOriginMethod($method), $arguments);
107
            } elseif ($this->instance instanceof CoreModel) {
108
                $result = $this->modelInjector($this->getOriginMethod($method), $arguments);
109
            } elseif ($this->instance instanceof CoreView) {
110
                $this->viewInjector($method, $arguments);
111
            } elseif ($this->instance instanceof CoreHelper) {
112
                $result = $this->helperInjector($this->getOriginMethod($method), $arguments);
113
            }
114
115
            return $result;
116
        } catch (DoctrineAnnotationException $e) {
117
            throw new AnnotationException($e);
118
        } catch (DelegateException $e) {
119
            // すでにデリゲート済み例外の場合はそのままスロー
120
            // カスタムアノテーション定義で発生する
121
            throw $e;
122
        } catch (\Exception $e) {
123
            $exceptionClass = get_class($e);
124
            switch ($exceptionClass) {
125
                case "Exception":
126
                case "LogicException":
127
                    $e = new ApplicationException($e->getMessage(), 500, $e);
128
                    break;
129
                case "RuntimeException":
130
                    $e = new SystemException($e->getMessage(), 500, $e);
131
                    break;
132
            }
133
134
            $exception = new ExceptionDelegator($this->getInstance(), $e, $method);
135
            $exception->inject('logger', $this->logger);
136
137
            if ($this->annotation !== null && is_array($this->annotation->exceptionHandler)) {
138
                $exception->setExceptionHandler($this->annotation->exceptionHandler);
139
            }
140
            $exception->raise();
141
        }
142
    }
143
144
    /**
145
     * オリジナルのインスタンスを返却する
146
     * @return CoreInterface インスタンス
147
     */
148
    public function getInstance()
149
    {
150
        return $this->injectedInstance ?: $this->instance;
151
    }
152
153
    /**
154
     * メソッドを実行する
155
     * @param string メソッド名
156
     * @param array 引数リスト
157
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment メソッド名 at position 0 could not be parsed: Unknown type name 'メソッド名' at position 0 in メソッド名.
Loading history...
158
    private function execute($method, $arguments)
159
    {
160
        // serviceの場合、modelの探索に行くためエラーにはしない
161
        if (!($this->injectedInstance instanceof CoreService) && !method_exists($this->injectedInstance, $method)) {
162
            $class = get_class($this->injectedInstance);
163
            throw new MethodNotFoundException("${class}#${method} is not defined.");
164
        }
165
166
        return call_user_func_array([$this->injectedInstance, $method], $arguments);
167
    }
168
169
    /**
170
     * Controllerに注入する
171
     * @param string メソッド名
172
     * @param array 引数リスト
173
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment メソッド名 at position 0 could not be parsed: Unknown type name 'メソッド名' at position 0 in メソッド名.
Loading history...
174
    private function controllerInjector($method, $arguments)
175
    {
176
        if (!method_exists($this->instance, $method)) {
177
            $this->injectedInstance = $this->instance;
178
            $this->instance = null;
179
            $class = get_class($this->instance);
180
            throw new MethodNotFoundException("${class}#${method} is not defined.");
181
        }
182
183
        $applicationInfo = $this->container->applicationInfo;
0 ignored issues
show
Bug Best Practice introduced by
The property applicationInfo does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
184
185
        // テンプレートキャッシュチェック
186
        $pageName = $this->container->coreDelegator->getPageName();
0 ignored issues
show
Bug introduced by
The method getPageName() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

186
        /** @scrutinizer ignore-call */ 
187
        $pageName = $this->container->coreDelegator->getPageName();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
Bug Best Practice introduced by
The property coreDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
187
        $cacheFile = $applicationInfo->cachePrefix . $this->camel2snake($pageName) . "-" . $this->camel2snake($method);
0 ignored issues
show
Bug introduced by
The property cachePrefix does not exist on string.
Loading history...
188
189
        $factory = new CacheDriverFactory();
190
        $config = new Container(false);
191
        $config->cacheDir = $applicationInfo->applicationRoot . "/app/views/" . $applicationInfo->cacheDir;
0 ignored issues
show
Bug introduced by
The property applicationRoot does not exist on string.
Loading history...
Bug Best Practice introduced by
The property cacheDir does not exist on WebStream\Container\Container. Since you implemented __set, consider adding a @property annotation.
Loading history...
Bug introduced by
The property cacheDir does not exist on string.
Loading history...
192
        $config->classPrefix = "view_cache";
0 ignored issues
show
Bug Best Practice introduced by
The property classPrefix does not exist on WebStream\Container\Container. Since you implemented __set, consider adding a @property annotation.
Loading history...
193
        $cache = $factory->create("WebStream\Cache\Driver\TemporaryFile", $config);
194
        $cache->inject('logger', $this->logger);
195
        $data = $cache->get($cacheFile);
196
197
        if ($data !== null) {
198
            $this->logger->debug("Template cache read success: $cacheFile.cache");
199
            echo $data;
200
201
            return;
202
        }
203
204
        $resolver = new Resolver($this->container);
205
        $model = $resolver->runService() ?: $resolver->runModel();
206
207
        // アノテーション注入処理は1度しか行わない
208
        if ($this->injectedInstance === null) {
209
            $annotation = $this->container->annotationDelegator->read($this->instance, $method);
0 ignored issues
show
Bug Best Practice introduced by
The property annotationDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
Bug introduced by
The method read() does not exist on null. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

209
            /** @scrutinizer ignore-call */ 
210
            $annotation = $this->container->annotationDelegator->read($this->instance, $method);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
210
            $annotationClosure = function ($classpath) use ($annotation) {
211
                if (array_key_exists($classpath, $annotation->annotationInfoList)) {
212
                    return $annotation->annotationInfoList[$classpath];
213
                }
214
                return null;
215
            };
216
217
            // @Header
218
            $header = $annotationClosure(Header::class);
0 ignored issues
show
Unused Code introduced by
The assignment to $header is dead and can be removed.
Loading history...
219
            // $mimeType = $this->annotation->header->mimeType;
220
221
            // @Filter
222
            $filter = $annotationClosure(Filter::class);
223
224
            // @Template
225
            $template = $annotationClosure(Template::class);
226
227
228
            // $template = $this->annotation->template;
229
230
            // custom annotation
231
            // $this->instance->__customAnnotation($this->annotation->customAnnotations);
232
233
            // 各アノテーションでエラーがあった場合この時点で例外を起こす。
234
            // 例外発生を遅延実行させないとエラーになっていないアノテーション情報が取れない
235
            $exception = $annotation->exception;
236
            if ($exception instanceof ExceptionDelegator) {
237
                if ($this->annotation->exceptionHandler !== null) {
238
                    $this->exceptionHandler = $this->annotation->exceptionHandler;
239
                }
240
                $exception->inject('logger', $this->logger);
241
                $exception->setExceptionHandler($this->exceptionHandler);
242
                $exception->raise();
243
            }
244
245
            // initialize filter
246
            $container = $this->container;
247
            $container->model = $model;
0 ignored issues
show
Bug Best Practice introduced by
The property model does not exist on WebStream\Container\Container. Since you implemented __set, consider adding a @property annotation.
Loading history...
248
            foreach ($filter->initialize as $refMethod) {
249
                $refMethod->invokeArgs($this->instance, [$container]);
250
            }
251
252
            // before filter
253
            foreach ($filter->before as $refMethod) {
254
                $refMethod->invoke($this->instance);
255
            }
256
257
            $this->injectedInstance = $this->instance;
258
            $this->execute($method, $arguments);
259
260
            // draw template
261
            if ($template !== null) {
262
                $view = $resolver->runView();
263
                $view->setTemplateEngine($template->engine);
264
                $view->draw([
265
                    "model" => $model,
266
                    "helper" => $resolver->runHelper(),
267
                    "mimeType" => $mimeType
0 ignored issues
show
Comprehensibility Best Practice introduced by
The variable $mimeType seems to be never defined.
Loading history...
268
                ]);
269
270
                if ($template->cacheTime !== null) {
271
                    $cacheFile = $applicationInfo->cachePrefix . $this->camel2snake($pageName) . "-" . $this->camel2snake($method);
272
                    $view->templateCache($cacheFile, ob_get_contents(), $template->cacheTime);
273
                }
274
            }
275
276
            // after filter
277
            foreach ($filter->after as $refMethod) {
278
                $refMethod->invoke($this->injectedInstance);
279
            }
280
281
            $this->instance = null;
282
        }
283
    }
284
285
    /**
286
     * Serviceに注入する
287
     * @param string メソッド名
288
     * @param array 引数リスト
289
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment メソッド名 at position 0 could not be parsed: Unknown type name 'メソッド名' at position 0 in メソッド名.
Loading history...
290
    private function serviceInjector($method, $arguments)
291
    {
292
        // アノテーション注入処理は1度しか行わない
293
        if ($this->injectedInstance === null) {
294
            $this->annotation = $this->container->annotationDelegator->read($this->instance, $method);
0 ignored issues
show
Bug Best Practice introduced by
The property annotationDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
295
296
            // @Filter
297
            $filter = $this->annotation->filter;
298
299
            // @ExceptionHandler
300
            $this->exceptionHandler = $this->annotation->exceptionHandler;
301
302
            // custom annotation
303
            $this->instance->__customAnnotation($this->annotation->customAnnotations);
304
305
            // 各アノテーションでエラーがあった場合この時点で例外を起こす。
306
            // 例外発生を遅延実行させないとエラーになっていないアノテーション情報が取れない
307
            $exception = $this->annotation->exception;
308
            if ($exception instanceof ExceptionDelegator) {
309
                if ($this->annotation->exceptionHandler !== null) {
310
                    $this->exceptionHandler = $this->annotation->exceptionHandler;
311
                }
312
                $exception->inject('logger', $this->logger);
313
                $exception->setExceptionHandler($this->exceptionHandler);
314
                $exception->raise();
315
            }
316
317
            foreach ($filter->initialize as $refMethod) {
318
                $refMethod->invokeArgs($this->instance, [$this->container]);
319
            }
320
321
            $this->injectedInstance = $this->instance;
322
            $this->instance = null;
323
        }
324
325
        return $this->execute($method, $arguments);
326
    }
327
328
    /**
329
     * Modelに注入する
330
     * @param string メソッド名
331
     * @param array 引数リスト
332
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment メソッド名 at position 0 could not be parsed: Unknown type name 'メソッド名' at position 0 in メソッド名.
Loading history...
333
    private function modelInjector($method, $arguments)
334
    {
335
        // アノテーション注入処理は1度しか行わない
336
        if ($this->injectedInstance === null) {
337
            $this->annotation = $this->container->annotationDelegator->read($this->instance, $method);
0 ignored issues
show
Bug Best Practice introduced by
The property annotationDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
338
339
            // @Filter
340
            $filter = $this->annotation->filter;
341
342
            // custom annotation
343
            $this->instance->__customAnnotation($this->annotation->customAnnotations);
344
345
            if ($this->exceptionHandler === null) {
0 ignored issues
show
introduced by
The condition $this->exceptionHandler === null can never be true.
Loading history...
346
                $this->exceptionHandler = $this->annotation->exceptionHandler;
347
            }
348
349
            // 各アノテーションでエラーがあった場合この時点で例外を起こす。
350
            // 例外発生を遅延実行させないとエラーになっていないアノテーション情報が取れない
351
            $exception = $this->annotation->exception;
352
            if ($exception instanceof ExceptionDelegator) {
353
                if ($this->annotation->exceptionHandler !== null) {
354
                    $this->exceptionHandler = $this->annotation->exceptionHandler;
355
                }
356
                $exception->inject('logger', $this->logger);
357
                $exception->setExceptionHandler($this->annotation->exceptionHandler);
358
                $exception->raise();
359
            }
360
361
            $initializeContainer = new Container(false);
362
            $initializeContainer->connectionContainerList = $this->annotation->database;
0 ignored issues
show
Bug Best Practice introduced by
The property connectionContainerList does not exist on WebStream\Container\Container. Since you implemented __set, consider adding a @property annotation.
Loading history...
363
            $initializeContainer->queryAnnotations = $this->annotation->query;
0 ignored issues
show
Bug Best Practice introduced by
The property queryAnnotations does not exist on WebStream\Container\Container. Since you implemented __set, consider adding a @property annotation.
Loading history...
364
365
            foreach ($filter->initialize as $refMethod) {
366
                $refMethod->invokeArgs($this->instance, [$initializeContainer]);
367
            }
368
369
            $this->injectedInstance = $this->instance;
370
            $this->instance = null;
371
        }
372
373
        return $this->execute($method, $arguments);
374
    }
375
376
    /**
377
     * Viewに注入する
378
     * @param string メソッド名
379
     * @param array 引数リスト
380
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment メソッド名 at position 0 could not be parsed: Unknown type name 'メソッド名' at position 0 in メソッド名.
Loading history...
381
    private function viewInjector($method, $arguments)
382
    {
383
        // アノテーション注入処理は1度しか行わない
384
        if ($this->injectedInstance === null) {
385
            $this->annotation = $this->container->annotationDelegator->read($this->instance, $method);
0 ignored issues
show
Bug Best Practice introduced by
The property annotationDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
386
387
            // @Filter
388
            $filter = $this->annotation->filter;
389
390
            // 各アノテーションでエラーがあった場合この時点で例外を起こす。
391
            // 例外発生を遅延実行させないとエラーになっていないアノテーション情報が取れない
392
            $exception = $this->annotation->exception;
393
            if ($exception instanceof ExceptionDelegator) {
394
                $exception->inject('logger', $this->logger);
395
                $exception->raise();
396
            }
397
398
            foreach ($filter->initialize as $refMethod) {
399
                $refMethod->invokeArgs($this->instance, [$this->container]);
400
            }
401
402
            $this->injectedInstance = $this->instance;
403
            $this->instance = null;
404
        }
405
406
        $this->execute($method, $arguments);
407
    }
408
409
    /**
410
     * Helperに注入する
411
     * @param string メソッド名
412
     * @param array 引数リスト
413
     */
0 ignored issues
show
Documentation Bug introduced by
The doc comment メソッド名 at position 0 could not be parsed: Unknown type name 'メソッド名' at position 0 in メソッド名.
Loading history...
414
    private function helperInjector($method, $arguments)
415
    {
416
        // アノテーション注入処理は1度しか行わない
417
        if ($this->injectedInstance === null) {
418
            $this->annotation = $this->container->annotationDelegator->read($this->instance, $method);
0 ignored issues
show
Bug Best Practice introduced by
The property annotationDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
419
420
            // @Filter
421
            $filter = $this->annotation->filter;
422
423
            // custom annotation
424
            $this->instance->__customAnnotation($this->annotation->customAnnotations);
425
426
            if ($this->exceptionHandler === null) {
0 ignored issues
show
introduced by
The condition $this->exceptionHandler === null can never be true.
Loading history...
427
                $this->exceptionHandler = $this->annotation->exceptionHandler;
428
            }
429
430
            // 各アノテーションでエラーがあった場合この時点で例外を起こす。
431
            // 例外発生を遅延実行させないとエラーになっていないアノテーション情報が取れない
432
            $exception = $this->annotation->exception;
433
            if ($exception instanceof ExceptionDelegator) {
434
                if ($this->annotation->exceptionHandler !== null) {
435
                    $this->exceptionHandler = $this->annotation->exceptionHandler;
436
                }
437
                $exception->inject('logger', $this->logger);
438
                $exception->setExceptionHandler($this->annotation->exceptionHandler);
439
                $exception->raise();
440
            }
441
442
            foreach ($filter->initialize as $refMethod) {
443
                $refMethod->invokeArgs($this->instance, [$this->container]);
444
            }
445
446
            $this->injectedInstance = $this->instance;
447
            $this->instance = null;
448
        }
449
450
        return $this->execute($method, $arguments);
451
    }
452
453
    /**
454
     * 実メソッド名を返却する
455
     * @param  stirng $method エイリアスメソッド名
0 ignored issues
show
Bug introduced by
The type WebStream\Delegate\stirng was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
456
     * @return stirng 実メソッド名
457
     */
458
    private function getOriginMethod($method)
459
    {
460
        // 実メソッドが定義済みの場合、エイリアスメソッド参照はしない
461
        if (method_exists($this->instance, $method)) {
462
            return $method;
463
        }
464
465
        $annotation = $this->container->annotationDelegator->read($this->instance, $method, "WebStream\Annotation\Attributes\Alias");
0 ignored issues
show
Bug Best Practice introduced by
The property annotationDelegator does not exist on WebStream\Container\Container. Since you implemented __get, consider adding a @property annotation.
Loading history...
466
467
        $originMethod = null;
468
        foreach ($annotation->alias as $alias) {
469
            if ($originMethod !== null && $alias->{$method} !== null) {
470
                throw new AnnotationException("Alias method of the same name is defined: $method");
471
            }
472
            if ($alias->{$method} !== null) {
473
                $originMethod = $alias->{$method};
474
            }
475
        }
476
477
        if ($originMethod !== null) {
478
            $class = get_class($this->instance);
479
            $this->logger->debug("Alias method found. Transfer from ${class}#${method} to ${class}#${originMethod}.");
480
        } else {
481
            $originMethod = $method;
482
        }
483
484
        return $originMethod;
485
    }
486
}
487