Skip to content

Commit

Permalink
Merge 89d8a3d into ecbc45d
Browse files Browse the repository at this point in the history
  • Loading branch information
jaredk2g committed Dec 9, 2021
2 parents ecbc45d + 89d8a3d commit 8211e35
Show file tree
Hide file tree
Showing 8 changed files with 39 additions and 42 deletions.
5 changes: 1 addition & 4 deletions src/Driver/AbstractDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ public function serializeValue($value)
/**
* Serializes an array of values.
*
* @param array $values
*
* @return array
*/
protected function serialize(array $values)
Expand Down Expand Up @@ -124,14 +122,13 @@ protected function prefixColumn($column, $tablename)
/**
* Adds join conditions to a select query.
*
* @param Query $query
* @param string $tablename
* @param SelectQuery $dbQuery
*/
protected function addJoins(Query $query, $tablename, $dbQuery)
{
foreach ($query->getJoins() as $join) {
list($foreignModelClass, $column, $foreignKey) = $join;
[$foreignModelClass, $column, $foreignKey] = $join;

$foreignModel = new $foreignModelClass();
$foreignTablename = $foreignModel->getTablename();
Expand Down
20 changes: 10 additions & 10 deletions src/Driver/DatabaseDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ public function getConnection(?string $id): QueryBuilder
try {
if ($id) {
return $this->connections->get($id);
} else {
return $this->connections->getDefault();
}
} catch (JAQBException | PDOException $e) {

return $this->connections->getDefault();
} catch (JAQBException|PDOException $e) {
throw new DriverException($e->getMessage(), $e->getCode(), $e);
}
}
Expand All @@ -108,8 +108,8 @@ public function createModel(Model $model, array $parameters)

try {
return $db->insert($values)
->into($tablename)
->execute() instanceof PDOStatement;
->into($tablename)
->execute() instanceof PDOStatement;
} catch (PDOException $original) {
throw new DriverException('An error occurred in the database driver when creating the '.$model::modelName().': '.$original->getMessage(), $original->getCode(), $original);
}
Expand Down Expand Up @@ -157,9 +157,9 @@ public function updateModel(Model $model, array $parameters): bool

try {
return $db->update($tablename)
->values($values)
->where($model->ids())
->execute() instanceof PDOStatement;
->values($values)
->where($model->ids())
->execute() instanceof PDOStatement;
} catch (PDOException $original) {
throw new DriverException('An error occurred in the database driver when updating the '.$model::modelName().': '.$original->getMessage(), $original->getCode(), $original);
}
Expand All @@ -172,8 +172,8 @@ public function deleteModel(Model $model): bool

try {
return $db->delete($tablename)
->where($model->ids())
->execute() instanceof PDOStatement;
->where($model->ids())
->execute() instanceof PDOStatement;
} catch (PDOException $original) {
throw new DriverException('An error occurred in the database driver while deleting the '.$model::modelName().': '.$original->getMessage(), $original->getCode(), $original);
}
Expand Down
4 changes: 2 additions & 2 deletions src/Driver/DbalDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ private function buildSelectQuery(Query $query, string $tablename): SelectQuery
/**
* Executes a select query through DBAL and returns a scalar result.
*
* @return false|mixed
*
* @throws DriverException
*
* @return false|mixed
*/
private function executeScalar(SelectQuery $query, Model $model, string $field)
{
Expand Down
28 changes: 14 additions & 14 deletions src/Driver/DriverInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,19 +23,19 @@ interface DriverInterface
/**
* Creates a model.
*
* @return mixed result
*
* @throws DriverException when an exception occurs within the driver
*
* @return mixed result
*/
public function createModel(Model $model, array $parameters);

/**
* Gets the last inserted ID. Used for drivers that generate
* IDs for models after creation.
*
* @return mixed
*
* @throws DriverException when an exception occurs within the driver
*
* @return mixed
*/
public function getCreatedId(Model $model, string $propertyName);

Expand All @@ -49,9 +49,9 @@ public function loadModel(Model $model): ?array;
/**
* Performs a query to find models of the given type.
*
* @return array raw data from storage
*
* @throws DriverException when an exception occurs within the driver
*
* @return array raw data from storage
*/
public function queryModels(Query $query): array;

Expand Down Expand Up @@ -79,36 +79,36 @@ public function count(Query $query): int;
/**
* Gets the sum matching the given query.
*
* @return number
*
* @throws DriverException when an exception occurs within the driver
*
* @return number
*/
public function sum(Query $query, string $field);

/**
* Gets the average matching the given query.
*
* @return number
*
* @throws DriverException when an exception occurs within the driver
*
* @return number
*/
public function average(Query $query, string $field);

/**
* Gets the max matching the given query.
*
* @return number
*
* @throws DriverException when an exception occurs within the driver
*
* @return number
*/
public function max(Query $query, string $field);

/**
* Gets the min matching the given query.
*
* @return number
*
* @throws DriverException when an exception occurs within the driver
*
* @return number
*/
public function min(Query $query, string $field);

Expand Down
12 changes: 6 additions & 6 deletions src/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -581,9 +581,9 @@ public function saveOrFail()
*
* @param array $data optional key-value properties to set
*
* @return bool true when the operation was successful
*
* @throws BadMethodCallException when called on an existing model
*
* @return bool true when the operation was successful
*/
public function create(array $data = []): bool
{
Expand Down Expand Up @@ -963,9 +963,9 @@ public function dirty(?string $name = null, bool $hasChanged = false): bool
*
* @param array $data optional key-value properties to set
*
* @return bool true when the operation was successful
*
* @throws BadMethodCallException when not called on an existing model
*
* @return bool true when the operation was successful
*/
public function set(array $data = []): bool
{
Expand Down Expand Up @@ -1200,9 +1200,9 @@ public static function find($id)
*
* @param mixed $id
*
* @return static
*
* @throws ModelNotFoundException when a model could not be found
*
* @return static
*/
public static function findOrFail($id)
{
Expand Down
6 changes: 3 additions & 3 deletions src/Property.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ final class Property implements ArrayAccess
private $name;

/** @var string|null */
private $type = null;
private $type;

/** @var string */
private $mutable = self::MUTABLE;
Expand All @@ -27,10 +27,10 @@ final class Property implements ArrayAccess
private $required = false;

/** @var array|string|null */
private $validate = null;
private $validate;

/** @var mixed|null */
private $default = null;
private $default;

/** @var bool */
private $hasDefault;
Expand Down
4 changes: 2 additions & 2 deletions src/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,9 @@ public static function to_date($value): int
{
if (!is_numeric($value)) {
return strtotime($value);
} else {
return $value + 0;
}

return $value + 0;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

require __DIR__.'/../vendor/autoload.php';

function modelValidate(&$value, array $options, \Pulsar\Model $model)
function modelValidate(&$value, array $options, Pulsar\Model $model)
{
$model->getErrors()->add('Custom error message from callable', ['field' => $options['field']]);

Expand Down

0 comments on commit 8211e35

Please sign in to comment.