| Total Complexity | 13 |
| Total Lines | 94 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | class Builder extends Base |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * Get the hydrated models without eager loading. |
||
| 17 | * |
||
| 18 | * @param array $columns |
||
| 19 | * @return \Illuminate\Database\Eloquent\Model[] |
||
| 20 | */ |
||
| 21 | 314 | public function getModels($columns = ['*']) |
|
| 22 | { |
||
| 23 | 314 | $items = $this->query->get($columns)->all(); |
|
| 24 | |||
| 25 | 314 | if ($this->getConnection() instanceof PostgresConnection) { |
|
|
|
|||
| 26 | 82 | $path = $this->model->getPathName(); |
|
| 27 | |||
| 28 | 82 | if (isset($items[0]->$path)) { |
|
| 29 | 37 | $this->replacePathSeparator( |
|
| 30 | 37 | $items, |
|
| 31 | $path, |
||
| 32 | 37 | $this->model->getPathSeparator() |
|
| 33 | ); |
||
| 34 | |||
| 35 | 37 | foreach ($this->model->getCustomPaths() as $path) { |
|
| 36 | 37 | $this->replacePathSeparator( |
|
| 37 | 37 | $items, |
|
| 38 | 37 | $path['name'], |
|
| 39 | 37 | $path['separator'] |
|
| 40 | ); |
||
| 41 | } |
||
| 42 | } |
||
| 43 | } |
||
| 44 | |||
| 45 | 314 | $table = (new $this->model())->getTable(); |
|
| 46 | |||
| 47 | 314 | $models = $this->model->hydrate($items)->each->setTable($table); |
|
| 48 | |||
| 49 | 314 | return $models->all(); |
|
| 50 | } |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Replace the separator in a PostgreSQL path column. |
||
| 54 | * |
||
| 55 | * @param array $items |
||
| 56 | * @param string $path |
||
| 57 | * @param string $separator |
||
| 58 | * @return void |
||
| 59 | */ |
||
| 60 | 37 | protected function replacePathSeparator(array $items, $path, $separator) |
|
| 61 | { |
||
| 62 | 37 | foreach ($items as $item) { |
|
| 63 | 37 | $item->$path = str_replace( |
|
| 64 | 37 | ',', |
|
| 65 | $separator, |
||
| 66 | 37 | substr($item->$path, 1, -1) |
|
| 67 | ); |
||
| 68 | } |
||
| 69 | 37 | } |
|
| 70 | |||
| 71 | /** |
||
| 72 | * Get the expression grammar. |
||
| 73 | * |
||
| 74 | * @return \Staudenmeir\LaravelAdjacencyList\Query\Grammars\ExpressionGrammar |
||
| 75 | */ |
||
| 76 | 250 | public function getExpressionGrammar() |
|
| 92 | } |
||
| 93 | |||
| 94 | /** |
||
| 95 | * Register all passed global scopes. |
||
| 96 | * |
||
| 97 | * @param array $scopes |
||
| 98 | * @return $this |
||
| 99 | */ |
||
| 100 | 68 | public function withGlobalScopes(array $scopes) |
|
| 109 |