MCPcopy Create free account
hub / github.com/VemtoOrg/vemto2 / getFormatted

Method getFormatted

src/php/common/ModelRepository.php:22–193  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

20 }
21
22 public function getFormatted(): array {
23 $models = $this->get();
24
25 $formattedModels = [];
26
27 foreach ($models as $model) {
28 $allImports = $this->getAllImports($model);
29
30 $allImports = collect($allImports)->map(function ($importData) {
31 return $this->buildImportStatementFromData($importData);
32 })->values()->toArray();
33
34 $reflection = new \ReflectionClass($model['class']);
35
36 // get the model parent class
37 $parentClass = $reflection->getParentClass();
38
39 // get the model interfaces
40 $interfaces = $reflection->getInterfaces();
41
42 // remove interfaces that are implemented by the parent class
43 $interfaces = collect($interfaces)->filter(function ($interface) use ($parentClass) {
44 return ! $parentClass || ! $parentClass->implementsInterface($interface->name);
45 })->values()->toArray();
46 $interfaces = collect($interfaces)->map(function ($interface) use ($model) {
47 return $this->buildImportStatement($model, $interface);
48 })->values()->toArray();
49
50 // get the model traits
51 $traits = collect($reflection->getTraits())->map(function ($trait) use ($model) {
52 return $this->buildImportStatement($model, $trait);
53 })->values()->toArray();
54
55 // remove traits from allImports (because the regex to get the imports also gets the traits)
56 $traitsShortNames = collect($reflection->getTraits())->map(function ($trait) {
57 return $trait->getShortName();
58 })->values()->toArray();
59 $allImports = collect($allImports)->filter(function ($import) use ($traitsShortNames) {
60 return ! in_array($import, $traitsShortNames);
61 })->values()->toArray();
62
63 $properties = $reflection->getDefaultProperties();
64
65 $fillable = $properties['fillable'] ?? [];
66 $casts = $properties['casts'] ?? [];
67 $dates = $properties['dates'] ?? [];
68 $hidden = $properties['hidden'] ?? [];
69 $appends = $properties['appends'] ?? [];
70 $guarded = $properties['guarded'] ?? [];
71
72 $allMethods = $reflection->getMethods();
73 $allTraitNames = $reflection->getTraitNames();
74 $extendsClass = $reflection->getParentClass();
75 $classMethods = collect($allMethods)->filter(function ($method) use ($model) {
76 return $method->getFileName() == $model['fullPath'];
77 });
78
79 $methods = [];

Callers

nothing calls this directly

Calls 15

getMethod · 0.95
getAllImportsMethod · 0.95
buildImportStatementMethod · 0.95
toArrayMethod · 0.80
getParentClassMethod · 0.80
getInterfacesMethod · 0.80
filterMethod · 0.80
getTraitsMethod · 0.80
getMethodsMethod · 0.80
getFileNameMethod · 0.80
getForeignKeyNameMethod · 0.80

Tested by

no test coverage detected