Skip to content

Commit

Permalink
refactor: throw expression
Browse files Browse the repository at this point in the history
  • Loading branch information
noelma committed May 21, 2023
1 parent c721662 commit 79bf904
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 30 deletions.
16 changes: 6 additions & 10 deletions src/Schema.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,11 +202,9 @@ public function getSchema(): array
*/
public function getTableSchema(string $tableName): Table
{
if (!$this->hasTable($tableName)) {
throw new TableNotFoundException($tableName);
}

return $this->getSchema()[ $tableName ];
return $this->hasTable($tableName)
? $this->getSchema()[ $tableName ]
: throw new TableNotFoundException($tableName);
}

/**
Expand Down Expand Up @@ -251,11 +249,9 @@ public function dropSchema(): self
*/
public function createTable(string $tableName, ?callable $callback = null): self
{
if ($this->hasTable($tableName)) {
throw new Exception(sprintf('Table %s exist.', $tableName));
}

$this->schema[ $tableName ] = self::tableBuilder($tableName, $callback)->getTable();
$this->schema[ $tableName ] = $this->hasTable($tableName)
? throw new Exception(sprintf('Table %s exist.', $tableName))
: self::tableBuilder($tableName, $callback)->getTable();

$this->save($this->name, $this->toArray());
$this->create($tableName);
Expand Down
8 changes: 3 additions & 5 deletions src/Table.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,11 +54,9 @@ public function addField(Field $field): void

public function getField(string $name): Field
{
if (!isset($this->fields[ $name ])) {
throw new \Exception();
}

return $this->fields[ $name ];
return isset($this->fields[ $name ])
? $this->fields[ $name ]
: throw new \Exception();
}

/**
Expand Down
8 changes: 3 additions & 5 deletions src/TableBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,9 @@ public function float(string $name): Field
*/
public function increments(string $name): Field
{
if ($this->table->getIncrement() !== null) {
throw new TableBuilderException('Only one incremental column is allowed per table.');
}

return $this->table->getFieldOrPut(new IncrementType($name));
return $this->table->getIncrement() !== null
? throw new TableBuilderException('Only one incremental column is allowed per table.')
: $this->table->getFieldOrPut(new IncrementType($name));
}

/**
Expand Down
19 changes: 9 additions & 10 deletions src/WhereHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,16 +67,15 @@ public function where(
$condition = $this->tryOperator($operator);

if (in_array($condition, [ 'like', 'ilike', 'not like', 'not ilike' ])) {
if (!\is_string($value)) {
throw new QueryException();
}
$this->like(
$columnName,
$condition,
$value,
$bool,
str_contains($condition, 'not')
);
\is_string($value)
? $this->like(
$columnName,
$condition,
$value,
$bool,
str_contains($condition, 'not')
)
: throw new QueryException();

return $this;
}
Expand Down

0 comments on commit 79bf904

Please sign in to comment.