Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.1, 8.2]
laravel: [9.*, 10.*]
php: [8.4, 8.5]
laravel: [13.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 9.*
- laravel: 10.*
- laravel: 13.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,16 @@
],
"require": {
"php": "^8.1",
"illuminate/contracts": "~9.0|~10.0|~11.0|~12.0|~13.0",
"illuminate/database": "~9.0|~10.0|~11.0|~12.0|~13.0",
"illuminate/events": "~9.0|~10.0|~11.0|~12.0|~13.0",
"illuminate/support": "~9.0|~10.0|~11.0|~12.0|~13.0",
"illuminate/validation": "~9.0|~10.0|~11.0|~12.0|~13.0"
"illuminate/contracts": "~13.0",
"illuminate/database": "~13.0",
"illuminate/events": "~13.0",
"illuminate/support": "~13.0",
"illuminate/validation": "~13.0"
},
"require-dev": {
"mockery/mockery": "^1.4.4",
"phpunit/phpunit": "~9.0"
"phpunit/phpunit": "~12.0",
"laravel/pint": "^1.29"
Comment on lines 16 to +27
},
Comment on lines 24 to 28
"autoload": {
"psr-4": {
Expand Down
14 changes: 7 additions & 7 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="vendor/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/12.5/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Package Test Suite">
<directory suffix=".php">./tests/</directory>
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
4 changes: 2 additions & 2 deletions src/Injectors/UniqueInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ trait UniqueInjector
* if required.
*
* @param array $parameters
* @param string $field
* @param string $field
* @return string
*/
protected function prepareUniqueRule($parameters, $field)
Expand Down Expand Up @@ -51,6 +51,6 @@ protected function prepareUniqueRule($parameters, $field)
}
}

return 'unique:' . implode(',', $parameters);
return 'unique:'.implode(',', $parameters);
}
}
4 changes: 2 additions & 2 deletions src/Injectors/UniqueWithInjector.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ trait UniqueWithInjector
* Prepare a unique_with rule, adding the model identifier if required.
*
* @param array $parameters
* @param string $field
* @param string $field
* @return string
*/
protected function prepareUniqueWithRule($parameters, $field)
Expand All @@ -22,6 +22,6 @@ protected function prepareUniqueWithRule($parameters, $field)
}
}

return 'unique_with:' . implode(',', $parameters);
return 'unique_with:'.implode(',', $parameters);
}
}
34 changes: 17 additions & 17 deletions src/ValidatingInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

namespace Watson\Validating;

use Illuminate\Support\MessageBag;
use Illuminate\Support\Facades\Input;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\MessageBag;
use Illuminate\Validation\Factory;

interface ValidatingInterface
Expand All @@ -17,10 +17,10 @@ interface ValidatingInterface
*/
public function getValidating();

/**
/**
* Set whether the model should attempt validation on saving.
*
* @param bool $value
* @param bool $value
* @return void
*/
public function setValidating($value);
Expand All @@ -37,8 +37,9 @@ public function getThrowValidationExceptions();
* Set whether the model should raise an exception or
* return a boolean on a failed validation.
*
* @param bool $value
* @param bool $value
* @return void
*
* @throws InvalidArgumentException
*/
public function setThrowValidationExceptions($value);
Expand All @@ -55,16 +56,17 @@ public function getInjectUniqueIdentifier();
* Set the model to add unique identifier to rules when performing
* validation.
*
* @param bool $value
* @param bool $value
* @return void
*
* @throws InvalidArgumentException
*/
public function setInjectUniqueIdentifier($value);

/**
* Get the model.
*
* @return \Illuminate\Database\Eloquent\Model
* @return Model
*/
public function getModel();

Expand All @@ -85,22 +87,20 @@ public function getRules();
/**
* Set the global validation rules.
*
* @param array $rules
* @return void
*/
public function setRules(?array $rules = null);

/**
* Get the validation error messages from the model.
*
* @return \Illuminate\Support\MessageBag
* @return MessageBag
*/
public function getErrors();

/**
* Set the error messages.
*
* @param \Illuminate\Support\MessageBag $validationErrors
* @return void
*/
public function setErrors(MessageBag $validationErrors);
Expand All @@ -116,7 +116,8 @@ public function isValid();
* Returns if the model is valid, otherwise throws an exception.
*
* @return bool
* @throws \Watson\Validating\ValidationException
*
* @throws ValidationException
*/
public function isValidOrFail();

Expand All @@ -139,7 +140,8 @@ public function forceSave();
* instead of returning a boolean (which is the default behaviour).
*
* @return void
* @throws \Watson\Validating\ValidatingException
*
* @throws ValidatingException
*/
public function saveOrFail();

Expand All @@ -154,22 +156,20 @@ public function saveOrReturn();
/**
* Get the Validator instance
*
* @return \Illuminate\Validation\Factory
* @return Factory
*/
public function getValidator();

/**
* Set the Validator instance
*
* @param \Illuminate\Validation\Factory $validator
*/
public function setValidator(Factory $validator);

/**
* Throw a validation exception.
*
* @throws \Watson\Validating\ValidationException
*/
* @throws ValidationException
*/
public function throwValidationException();

/**
Expand Down
7 changes: 4 additions & 3 deletions src/ValidatingModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

namespace Watson\Validating;

use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Contracts\Support\MessageProvider;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Support\MessageBag;

abstract class ValidatingModel extends Eloquent implements MessageProvider, ValidatingInterface
{
/**
* Make model validate attributes.
*
* @see \Watson\Validating\ValidatingTrait
* @see ValidatingTrait
*/
use ValidatingTrait;

Expand All @@ -24,7 +25,7 @@ abstract class ValidatingModel extends Eloquent implements MessageProvider, Vali
/**
* Get the messages for the instance.
*
* @return \Illuminate\Support\MessageBag
* @return MessageBag
*/
public function getMessageBag()
{
Expand Down
22 changes: 8 additions & 14 deletions src/ValidatingObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,14 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\Event;
use Watson\Validating\ValidationException;

class ValidatingObserver
{
/**
* Register the validation event for saving the model. Saving validation
* should only occur if creating and updating validation does not.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return boolean
* @return bool
*/
public function saving(Model $model)
{
Expand All @@ -23,8 +21,7 @@ public function saving(Model $model)
/**
* Register the validation event for restoring the model.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return boolean
* @return bool
*/
public function restoring(Model $model)
{
Expand All @@ -34,9 +31,8 @@ public function restoring(Model $model)
/**
* Perform validation with the specified ruleset.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $event
* @return boolean
* @param string $event
* @return bool
*/
protected function performValidation(Model $model, $event)
{
Expand Down Expand Up @@ -68,24 +64,22 @@ protected function performValidation(Model $model, $event)
/**
* Fire the namespaced validating event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $event
* @param string $event
* @return mixed
*/
protected function fireValidatingEvent(Model $model, $event)
{
return Event::until("eloquent.validating: ".get_class($model), [$model, $event]);
return Event::until('eloquent.validating: '.get_class($model), [$model, $event]);
}

/**
* Fire the namespaced post-validation event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @param string $status
* @param string $status
* @return void
*/
protected function fireValidatedEvent(Model $model, $status)
{
Event::dispatch("eloquent.validated: ".get_class($model), [$model, $status]);
Event::dispatch('eloquent.validated: '.get_class($model), [$model, $status]);
}
}
Loading
Loading