Skip to content

Commit

Permalink
phpdoc and typehint cleanups
Browse files Browse the repository at this point in the history
  • Loading branch information
jarischaefer committed Mar 26, 2016
1 parent c91a1a9 commit 80379f8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 13 deletions.
10 changes: 3 additions & 7 deletions src/Jarischaefer/HalApi/Controllers/HalApiResourceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ abstract class HalApiResourceController extends HalApiController implements HalA
/**
* The model's transformer.
*
* @var HalApiTransformer
* @var HalApiTransformerContract
*/
protected $transformer;
/**
Expand Down Expand Up @@ -69,10 +69,10 @@ abstract class HalApiResourceController extends HalApiController implements HalA

/**
* @param HalApiControllerParameters $parameters
* @param HalApiTransformer $transformer
* @param HalApiTransformerContract $transformer
* @param Builder $schemaBuilder
*/
public function __construct(HalApiControllerParameters $parameters, HalApiTransformer $transformer, Builder $schemaBuilder)
public function __construct(HalApiControllerParameters $parameters, HalApiTransformerContract $transformer, Builder $schemaBuilder)
{
parent::__construct($parameters);

Expand All @@ -84,10 +84,6 @@ public function __construct(HalApiControllerParameters $parameters, HalApiTransf
$this->schemaBuilder = $schemaBuilder;
$this->model = static::getModel();

if (!is_subclass_of($this->transformer, HalApiTransformerContract::class)) {
throw new RuntimeException('Transformer must be child of ' . HalApiTransformerContract::class);
}

if (!is_subclass_of($this->model, Model::class)) {
throw new RuntimeException('Model must be child of ' . Model::class);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,11 @@

use Exception;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Jarischaefer\HalApi\Exceptions\BadPostRequestException;
use Jarischaefer\HalApi\Exceptions\BadPutRequestException;
use Jarischaefer\HalApi\Exceptions\DatabaseConflictException;
use Jarischaefer\HalApi\Exceptions\DatabaseSaveException;
use Jarischaefer\HalApi\Transformers\HalApiTransformer;
use Jarischaefer\HalApi\Transformers\HalApiTransformerContract;
use Symfony\Component\HttpFoundation\Response;

/**
Expand Down Expand Up @@ -39,11 +38,12 @@ public static function getModel();
* exception.
*
* If you do not typehint your method (take a look at the update method in this class), the variable passed
* will be null. Otherwise an instance of your model with the ->exists property set to false is passed.
* will be the original route parameter.
* Otherwise, an instance of your model with the ->exists property set to false is passed.
*
* public function update($user = null)
* public function update($user)
* {
* var_dump($user) // null if not found in database
* var_dump($user) // original route parameter (e.g. new resource's ID) if not found in database
* }
*
* public function update(User $user)
Expand All @@ -61,7 +61,7 @@ public static function getModelBindingCallback();
/**
* Returns an instance of a transformer to be used for all transformations in this controller.
*
* @return HalApiTransformer
* @return HalApiTransformerContract
*/
public function getTransformer();

Expand Down

0 comments on commit 80379f8

Please sign in to comment.