Skip to content

Commit

Permalink
many validations
Browse files Browse the repository at this point in the history
  • Loading branch information
luckyraul committed Jul 19, 2023
1 parent af3516d commit 2bb9974
Show file tree
Hide file tree
Showing 40 changed files with 556 additions and 376 deletions.
2 changes: 1 addition & 1 deletion src/Jeeves/Generators/Crud/Controllers/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ public function genAdminEditController(
. ');' . PHP_EOL
. '$resultPage->getConfig()->getTitle()->prepend(__(\'' . $entityName . '\')->render());' . PHP_EOL
. '$resultPage->getConfig()->getTitle()->prepend(' . PHP_EOL
. self::TAB . '$entity->getId() ? $entity->getTitle() : __(\'New ' . $entityName . '\')->render()' . PHP_EOL
. self::TAB . '$entityId ? $entity->getTitle() : __(\'New ' . $entityName . '\')->render()' . PHP_EOL
. ');' . PHP_EOL . PHP_EOL
. 'return $resultPage;');
$namespace->addUse('\Magento\Framework\Exception\NoSuchEntityException');
Expand Down
15 changes: 12 additions & 3 deletions src/Jeeves/Generators/Crud/Interfaces/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public function genModelInterface(
$pk[$name] = $value;
$pk[$name]['nullable'] = !$notNullable;
}
$generated = false;
if (isset($value['identity']) && $value['identity'] === true) {
$generated = true;
}
$interface->addConstant(strtoupper($name), strtolower($name))->setPublic();
$method = $this->snakeCaseToUpperCamelCase($name);
$get = $interface->addMethod('get' . $method)
Expand All @@ -58,7 +62,7 @@ public function genModelInterface(

if ($typehint) {
$get->setReturnType($this->convertType($value['type']));
$get->setReturnNullable(!$notNullable);
$get->setReturnNullable($generated ? true : !$notNullable);
$param->setNullable(!$notNullable);
$param->setType($this->convertType($value['type']));
$set->setReturnType('self');
Expand All @@ -84,6 +88,11 @@ public function genModelInterface(
if ($primary !== self::DEFAULT_KEY && count($pk) === 1) {
$item = current($pk);

$generated = false;
if (isset($item['identity']) && $item['identity'] === true) {
$generated = true;
}

$getId = $interface
->addMethod('getId')
->addComment('Get ID')
Expand All @@ -95,15 +104,15 @@ public function genModelInterface(

if ($typehint) {
$getId->setReturnType($this->convertType($item['type']));
$getId->setReturnNullable($item['nullable']);
$getId->setReturnNullable($generated ? true : $item['nullable']);
}

$setId = $interface
->addMethod('setId')
->addComment('Set ID')
->setVisibility('public');

$setIdParam = $setId->addParameter(self::DEFAULT_KEY);
$setId->addParameter(self::DEFAULT_KEY);
$setId->addComment('@param ' . $this->convertType($item['type']) . ' $id');

if ($hasApi || !$typehint) {
Expand Down
13 changes: 11 additions & 2 deletions src/Jeeves/Generators/Crud/Models/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,10 @@ public function genModel(
$pk[$name] = $value;
$pk[$name]['nullable'] = !$notNullable;
}
$generated = false;
if (isset($value['identity']) && $value['identity'] === true) {
$generated = true;
}
$method = $this->snakeCaseToUpperCamelCase($name);
$getter = $class->addMethod('get' . $method)
->addComment('Get ' . str_replace('_', ' ', $name))
Expand All @@ -76,7 +80,7 @@ public function genModel(

if ($typehint) {
$getter->setReturnType($this->convertType($value['type']));
$getter->setReturnNullable(!$notNullable);
$getter->setReturnNullable($generated ? true : !$notNullable);

$setter->setReturnType('self');
$setParam->setType($this->convertType($value['type']));
Expand All @@ -102,14 +106,19 @@ public function genModel(
$item = current($pk);
$itemName = current(array_keys($pk));

$generated = false;
if (isset($item['identity']) && $item['identity'] === true) {
$generated = true;
}

$getId = $class
->addMethod('getId')
->addComment('Get ID')
->setVisibility('public')
->setBody('return $this->getData(self::' . strtoupper($itemName) . ');');
if ($typehint) {
$getId->setReturnType($this->convertType($item['type']));
$getId->setReturnNullable($item['nullable']);
$getId->setReturnNullable($generated ? true : $item['nullable']);
}

$setId = $class
Expand Down
Loading

0 comments on commit 2bb9974

Please sign in to comment.