LaravelFreelancerNL /
laravel-arangodb
| 1 | <?php |
||||
| 2 | |||||
| 3 | declare(strict_types=1); |
||||
| 4 | |||||
| 5 | namespace LaravelFreelancerNL\Aranguent\Schema\Concerns; |
||||
| 6 | |||||
| 7 | use ArangoClient\Exceptions\ArangoException; |
||||
| 8 | |||||
| 9 | trait HandlesViews |
||||
| 10 | { |
||||
| 11 | /** |
||||
| 12 | * @param array<mixed> $properties |
||||
| 13 | * |
||||
| 14 | * @throws ArangoException |
||||
| 15 | */ |
||||
| 16 | 65 | public function createView(string $name, array $properties, string $type = 'arangosearch') |
|||
| 17 | { |
||||
| 18 | 65 | $view = $properties; |
|||
| 19 | 65 | $view['name'] = $name; |
|||
| 20 | 65 | $view['type'] = $type; |
|||
| 21 | |||||
| 22 | 65 | $this->schemaManager->createView($view); |
|||
| 23 | } |
||||
| 24 | |||||
| 25 | /** |
||||
| 26 | * @param string $name |
||||
| 27 | * @return mixed[] |
||||
| 28 | * @throws ArangoException |
||||
| 29 | */ |
||||
| 30 | 2 | public function getView(string $name): array |
|||
| 31 | { |
||||
| 32 | 2 | return (array) $this->schemaManager->getView($name); |
|||
| 33 | } |
||||
| 34 | |||||
| 35 | 59 | public function hasView($view) |
|||
| 36 | { |
||||
| 37 | 59 | return $this->handleExceptionsAsQueryExceptions(function () use ($view) { |
|||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 38 | 59 | return $this->schemaManager->hasView($view); |
|||
| 39 | 59 | }); |
|||
| 40 | } |
||||
| 41 | |||||
| 42 | /** |
||||
| 43 | * @param string|string[]|null $schema |
||||
| 44 | * @return mixed[] |
||||
| 45 | * @throws ArangoException |
||||
| 46 | */ |
||||
| 47 | 8 | public function getViews($schema = null): array |
|||
| 48 | { |
||||
| 49 | 8 | unset($schema); |
|||
| 50 | |||||
| 51 | 8 | return $this->mapResultsToArray( |
|||
|
0 ignored issues
–
show
It seems like
mapResultsToArray() must be provided by classes using this trait. How about adding it as abstract method to this trait?
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 52 | 8 | $this->schemaManager->getViews(), |
|||
| 53 | 8 | ); |
|||
| 54 | } |
||||
| 55 | |||||
| 56 | /** |
||||
| 57 | * @throws ArangoException |
||||
| 58 | */ |
||||
| 59 | 2 | public function editView(string $name, array $properties) |
|||
| 60 | { |
||||
| 61 | 2 | $this->schemaManager->updateView($name, $properties); |
|||
| 62 | } |
||||
| 63 | |||||
| 64 | /** |
||||
| 65 | * @throws ArangoException |
||||
| 66 | */ |
||||
| 67 | 2 | public function renameView(string $from, string $to) |
|||
| 68 | { |
||||
| 69 | 2 | $this->schemaManager->renameView($from, $to); |
|||
| 70 | } |
||||
| 71 | |||||
| 72 | /** |
||||
| 73 | * @throws ArangoException |
||||
| 74 | */ |
||||
| 75 | 2 | public function dropView(string $name) |
|||
| 76 | { |
||||
| 77 | 2 | $this->schemaManager->deleteView($name); |
|||
| 78 | } |
||||
| 79 | |||||
| 80 | /** |
||||
| 81 | * @throws ArangoException |
||||
| 82 | */ |
||||
| 83 | 59 | public function dropViewIfExists(string $name): bool |
|||
| 84 | { |
||||
| 85 | 59 | if ($this->hasView($name)) { |
|||
| 86 | 24 | $this->schemaManager->deleteView($name); |
|||
| 87 | } |
||||
| 88 | |||||
| 89 | 59 | return true; |
|||
| 90 | } |
||||
| 91 | |||||
| 92 | /** |
||||
| 93 | * Drop all views from the schema. |
||||
| 94 | * |
||||
| 95 | * @throws ArangoException |
||||
| 96 | */ |
||||
| 97 | 35 | public function dropAllViews(): void |
|||
| 98 | { |
||||
| 99 | 35 | $this->schemaManager->deleteAllViews(); |
|||
| 100 | } |
||||
| 101 | } |
||||
| 102 |