Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ npm-debug.log
yarn-error.log
.env
composer.lock
.php_cs.cache
.php_cs.cache
.phpunit.result.cache
20 changes: 9 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,21 @@ language: php

matrix:
include:
- php: "7.1"
env: LARAVEL_VERSION="5.5.*"
- php: "7.2"
env: LARAVEL_VERSION="5.5.*"
- php: "7.2"
env: LARAVEL_VERSION="5.6.*"
- php: "7.2"
env: LARAVEL_VERSION="5.7.*"
- php: "7.2"
env: LARAVEL_VERSION="5.8.*"
env: LARAVEL_VERSION="7.0.*"
- php: "7.3"
env: LARAVEL_VERSION="7.0.*"
- php: "7.4"
env: LARAVEL_VERSION="7.0.*"
- php: "7.3"
env: LARAVEL_VERSION="5.8.*" RUN_CS_FIXER=1
env: LARAVEL_VERSION="8.0.*"
- php: "7.4"
env: LARAVEL_VERSION="8.0.*" $RUN_CS_FIXER=1

sudo: false

install:
- composer require "illuminate/support:${LARAVEL_VERSION}" --no-update --no-interaction
- composer require "laravel/framework:${LARAVEL_VERSION}" --no-update --no-interaction
- travis_retry composer install --no-interaction --prefer-dist

script:
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ If you created your own routes make sure you have the ``auth:api`` middlware on
##### Laravel framework
* https://laravel.com/docs/

##### Dimsav / laravel-translatable
* https://github.com/dimsav/laravel-translatable
##### Astrotomic / laravel-translatable
* https://github.com/Astrotomic/laravel-translatable

## Change log

Expand Down
17 changes: 9 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,20 @@
}
],
"require": {
"php": ">=7.1.3",
"dimsav/laravel-translatable": "^8.0|^9.0",
"laravel/framework": "5.5.*|5.6.*|5.7.*|5.8.*"
"php": ">=7.2",
"ext-json": "*",
"astrotomic/laravel-translatable": "^11.6",
"laravel/framework": "^7.0|^8.0"
},
"require-dev": {
"filp/whoops": "~2.0",
"friendsofphp/php-cs-fixer": "^2.4",
"friendsofphp/php-cs-fixer": "^2.16",
"mockery/mockery": "^1.0",
"graham-campbell/testbench": "^4.0|^5.1",
"phpunit/php-code-coverage": "^5.3|^6.0",
"phpunit/phpunit": "^7.0|^6.1",
"orchestra/testbench": "^5.0|^6.0",
"phpunit/php-code-coverage": "^7.0",
"phpunit/phpunit": "^8.0",
"spatie/phpunit-watcher": "^1.3",
"squizlabs/php_codesniffer": "^2.3"
"squizlabs/php_codesniffer": "^3.5"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion resources/templates/model.stub
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
namespace $NAMESPACE_MODEL$;

use Illuminate\Database\Eloquent\Model;
use Dimsav\Translatable\Translatable;
use Astrotomic\Translatable\Translatable;

class $MODEL_NAME$ extends Model
{
Expand Down
2 changes: 1 addition & 1 deletion sample/Http/SampleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

class SampleController extends BaseApiController
{
/** @var RepositoryInterface $repository */
/** @var RepositoryInterface */
protected $repository;

public function __construct(SampleRepository $repository, Request $request)
Expand Down
2 changes: 1 addition & 1 deletion sample/Sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace App;

use Dimsav\Translatable\Translatable;
use Astrotomic\Translatable\Translatable;
use Illuminate\Database\Eloquent\Model;

class Sample extends Model
Expand Down
20 changes: 10 additions & 10 deletions sample/Tests/SampleAuthenticationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ public function setUp()
}

/** @test */
public function it_creates_an_sample_unauthenticated()
public function itCreatesAnSampleUnauthenticated()
{
$response = $this->post($this->baseUrl);
$response->assertStatus(401);
}

/** @test */
public function it_creates_an_sample_authenticated()
public function itCreatesAnSampleAuthenticated()
{
Passport::actingAs($this->user);

Expand All @@ -46,7 +46,7 @@ public function it_creates_an_sample_authenticated()
}

/** @test */
public function it_updates_an_sample_unauthenticated()
public function itUpdatesAnSampleUnauthenticated()
{
$sample = factory(Sample::class)->create();

Expand All @@ -55,7 +55,7 @@ public function it_updates_an_sample_unauthenticated()
}

/** @test */
public function it_updates_an_sample_authenticated()
public function itUpdatesAnSampleAuthenticated()
{
Passport::actingAs($this->user);

Expand All @@ -67,7 +67,7 @@ public function it_updates_an_sample_authenticated()
}

/** @test */
public function it_retrieves_an_sample_unauthenticated()
public function itRetrievesAnSampleUnauthenticated()
{
$sample = factory(Sample::class)->create();

Expand All @@ -76,7 +76,7 @@ public function it_retrieves_an_sample_unauthenticated()
}

/** @test */
public function it_retrieves_an_sample_authenticated()
public function itRetrievesAnSampleAuthenticated()
{
Passport::actingAs($this->user);

Expand All @@ -87,7 +87,7 @@ public function it_retrieves_an_sample_authenticated()
}

/** @test */
public function it_retrieves_all_samples_unauthenticated()
public function itRetrievesAllSamplesUnauthenticated()
{
factory(Sample::class, 3)->create();

Expand All @@ -96,7 +96,7 @@ public function it_retrieves_all_samples_unauthenticated()
}

/** @test */
public function it_retrieves_all_samples_authenticated()
public function itRetrievesAllSamplesAuthenticated()
{
Passport::actingAs($this->user);

Expand All @@ -107,7 +107,7 @@ public function it_retrieves_all_samples_authenticated()
}

/** @test */
public function it_deletes_an_sample_unauthenticated()
public function itDeletesAnSampleUnauthenticated()
{
$sample = factory(Sample::class)->create();

Expand All @@ -116,7 +116,7 @@ public function it_deletes_an_sample_unauthenticated()
}

/** @test */
public function it_deletes_an_sample_authenticated()
public function itDeletesAnSampleAuthenticated()
{
Passport::actingAs($this->user);

Expand Down
5 changes: 4 additions & 1 deletion src/Http/Controllers/Api/BaseApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@

abstract class BaseApiController extends Controller
{
use DispatchesJobs, ValidatesRequests, HandleResponses, AuthorizesRequests;
use AuthorizesRequests;
use DispatchesJobs;
use HandleResponses;
use ValidatesRequests;

protected $respondController;
protected $repository;
Expand Down
1 change: 0 additions & 1 deletion src/Http/Middleware/ConfigureLocale.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ class ConfigureLocale
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
*
* @return mixed
*/
Expand Down
3 changes: 0 additions & 3 deletions src/Http/Middleware/InspectContentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@
class InspectContentType
{
/**
* @param Request $request
* @param Closure $next
*
* @throws ContentTypeNotSupportedException
*
* @return mixed
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Resources/BaseApiCollectionResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function toArray($request)
protected function getIncludedRelationships($items, Request $request)
{
$includes = explode(',', $request->get('include', null));
if ($includes === []) {
if ([] === $includes) {
return [];
}
$relations = $this->includeCollectionRelationships($items, $includes);
Expand Down
11 changes: 6 additions & 5 deletions src/Http/Resources/BaseApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

use Illuminate\Database\Eloquent\Model;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\Resource;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Swis\JsonApi\Server\Traits\HandlesRelationships;

class BaseApiResource extends Resource
class BaseApiResource extends JsonResource
{
use HandlesRelationships;

Expand Down Expand Up @@ -43,7 +44,7 @@ public function setValues()
if (!$this->resource) {
return;
}
$this->resource->addHidden($this->resource->getKeyName());
$this->resource->makeHidden($this->resource->getKeyName());

$this->jsonApiModel->setId((string) $this->resource->getKey());
$this->jsonApiModel->setType($this->getResourceType());
Expand Down Expand Up @@ -193,7 +194,7 @@ protected function getRelationshipData($data)
}
}

if ($relationshipData->toArray(true) == []) {
if ([] == $relationshipData->toArray(true)) {
$relationshipData = [];
}
} elseif ($data instanceof Model) {
Expand Down Expand Up @@ -236,7 +237,7 @@ protected function getIncludedRelationships(Request $request)
protected function getResourceType()
{
$resourceClass = class_basename($this->resource);
$resourcePlural = str_plural($resourceClass);
$resourcePlural = Str::plural($resourceClass);

// Converts camelcase to dash
$lowerCaseResourceType = strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $resourcePlural));
Expand Down
7 changes: 4 additions & 3 deletions src/Http/Resources/IdentifierResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

namespace Swis\JsonApi\Server\Http\Resources;

use Illuminate\Http\Resources\Json\Resource;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Str;

class IdentifierResource extends Resource
class IdentifierResource extends JsonResource
{
/**
* Transform the resource into an array.
Expand All @@ -24,7 +25,7 @@ public function toArray($request)
protected function getResourceType()
{
$resourceClass = class_basename($this->resource);
$resourcePlural = str_plural($resourceClass);
$resourcePlural = Str::plural($resourceClass);
// Converts camelcase to dash
$lowerCaseResourceType = strtolower(preg_replace('/([a-zA-Z])(?=[A-Z])/', '$1-', $resourcePlural));

Expand Down
2 changes: 1 addition & 1 deletion src/Providers/LaravelApiServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Swis\JsonApi\Server\Providers;

use Dimsav\Translatable\TranslatableServiceProvider;
use Astrotomic\Translatable\TranslatableServiceProvider;
use Illuminate\Routing\Router;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Facades\Route;
Expand Down
5 changes: 2 additions & 3 deletions src/Repositories/BaseApiRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ abstract class BaseApiRepository implements RepositoryInterface
const PAGE = 1;
const PER_PAGE = 15;

/** @var Model $model */
/** @var Model */
protected $model;
protected $user;

protected $page = self::PAGE;
protected $perPage = self::PER_PAGE;
protected $parameters;

/** @var Builder $query */
/** @var Builder */
protected $query;
protected $columns = ['*'];

Expand Down Expand Up @@ -88,7 +88,6 @@ public function create(array $data)
}

/**
* @param array $data
* @param $objectKey
*
* @throws NotFoundException
Expand Down
12 changes: 7 additions & 5 deletions src/Services/CustomFileGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Swis\JsonApi\Server\Services;

use Illuminate\Support\Str;

class CustomFileGenerator
{
private $modelName;
Expand All @@ -11,11 +13,11 @@ protected function setStubVars()
{
$this->stubVariables = [
'$MODEL_NAME$' => $this->modelName,
'$CAMEL_CASE_MODEL_NAME$' => camel_case($this->modelName),
'$SNAKE_CASED_MODEL_NAME$' => strtolower(snake_case($this->modelName)),
'$PLURAL_SNAKE_CASED_MODEL_NAME$' => strtolower(str_plural(snake_case($this->modelName))),
'$PLURAL_UPPER_CASED_MODEL_NAME$' => strtoupper(str_plural($this->modelName)),
'$PLURAL_LOWER_CASED_MODEL_NAME$' => strtolower(str_plural($this->modelName)),
'$CAMEL_CASE_MODEL_NAME$' => Str::camel($this->modelName),
'$SNAKE_CASED_MODEL_NAME$' => strtolower(Str::snake($this->modelName)),
'$PLURAL_SNAKE_CASED_MODEL_NAME$' => strtolower(Str::plural(Str::snake($this->modelName))),
'$PLURAL_UPPER_CASED_MODEL_NAME$' => strtoupper(Str::plural($this->modelName)),
'$PLURAL_LOWER_CASED_MODEL_NAME$' => strtolower(Str::plural($this->modelName)),
'$UPPER_CASED_MODEL_NAME$' => strtoupper($this->modelName),
'$NAMESPACE_MODEL$' => config('laravel_api.namespace.model'),
'$NAME_SPACE_REPOSITORY$' => config('laravel_api.namespace.repository'),
Expand Down
Loading