-
Notifications
You must be signed in to change notification settings - Fork 0
/
Method.php
45 lines (35 loc) · 1.17 KB
/
Method.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
<?php
namespace PhpCTags\Finder\Position;
class Method extends Class_ implements Finder
{
public $class;
public function validate()
{
parent::validate();
if (! $this->class) {
throw new \Exception('Method Finder class is invalid');
}
}
public function find()
{
$this->validate();
require_once $this->getAutoloadFile();
try {
$class = $this->namespace ? $this->namespace.'\\'.$this->class : $this->class;
$refMethod = new \ReflectionMethod($class, $this->name);
} catch (\Exception $e) {
throw new \Exception('Reflection Method: '.$e->getMessage());
}
$file = $refMethod->getFileName();
if (! file_exists($file)) {
throw new \Exception("Method Finder file not found: $file");
}
$line = $refMethod->getStartLine();
if ($line <= 0) {
throw new \Exception("Method Finder line is invalid: $line");
}
$rows = file($file);
$raw = isset($rows[$line - 1]) ? $rows[$line - 1] : null;
return new \PhpCTags\Position($file, $line, stripos($raw, $this->name) + 1);
}
}