Skip to content
This repository was archived by the owner on Feb 27, 2024. It is now read-only.
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Prepare for laravel 6 use static metods
Change library from Dimsav to Astrotomic
Change composer requirements
Fix tests
  • Loading branch information
Julius committed Dec 11, 2019
commit ded776da7227727bd977d3007bd45048ef497782
16 changes: 6 additions & 10 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,19 @@ 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.*"
- php: "7.3"
env: LARAVEL_VERSION="5.8.*" RUN_CS_FIXER=1
env: LARAVEL_VERSION="5.8.*"
- php: "7.2"
env: LARAVEL_VERSION="6.0.*"
- php: "7.3"
env: LARAVEL_VERSION="6.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
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@
}
],
"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",
"astrotomic/laravel-translatable": "^11.6",
"laravel/framework": "^5.8|^6.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": "3.8.*|^4.0",
"phpunit/php-code-coverage": "^6.0|^7.0",
"phpunit/phpunit": "^7.0|^8.0",
"spatie/phpunit-watcher": "^1.3",
"squizlabs/php_codesniffer": "^2.3"
"squizlabs/php_codesniffer": "^2.3|^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/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
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 DispatchesJobs;
use ValidatesRequests;
use HandleResponses;
use AuthorizesRequests;

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
3 changes: 2 additions & 1 deletion src/Http/Resources/BaseApiResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\Resource;
use Illuminate\Support\Collection;
use Illuminate\Support\Str;
use Swis\JsonApi\Server\Traits\HandlesRelationships;

class BaseApiResource extends Resource
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
3 changes: 2 additions & 1 deletion src/Http/Resources/IdentifierResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Swis\JsonApi\Server\Http\Resources;

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

class IdentifierResource extends Resource
{
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
1 change: 0 additions & 1 deletion src/Repositories/BaseApiRepository.php
Original file line number Diff line number Diff line change
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
15 changes: 7 additions & 8 deletions src/Traits/HandlesRelationships.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Illuminate\Database\Eloquent\Relations\MorphTo;
use Illuminate\Database\Eloquent\Relations\MorphToMany;
use Illuminate\Http\Resources\Json\ResourceCollection;
use Illuminate\Support\Str;
use Swis\JsonApi\Server\Http\Resources\BaseApiResource;

trait HandlesRelationships
Expand Down Expand Up @@ -72,8 +73,8 @@ public function includeCollectionRelationships($items, $includes)
* Loops through all included tags. It checks for each include if there is a nested include.
* And also runs that recursively through includeCollectionRelationships.
*
* @param $item
* @param $includes
* @param mixed $item
* @param mixed $includes
*
* @return array
*/
Expand All @@ -90,7 +91,7 @@ protected function handleIncludes($item, $includes)
}
} else {
$included = BaseApiResource::make($item->$include);
$object = str_before($nestedInclude, '.');
$object = Str::before($nestedInclude, '.');
if (isset($included->$object)) {
$relationshipResources[] = $this->handleIncludes($included, [$nestedInclude]);
}
Expand Down Expand Up @@ -151,15 +152,13 @@ protected function removeDuplicates($items)

/**
* @param $include
*
* @return array
*/
protected function getNestedRelation($include): array
{
$nestedInclude = null;
if (str_contains($include, '.')) {
$nestedInclude = str_after($include, '.');
$include = str_before($include, '.');
if (Str::contains($include, '.')) {
$nestedInclude = Str::after($include, '.');
$include = Str::before($include, '.');
}

return [$nestedInclude, $include];
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/ControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function test_index()
{
$this->response = $this->testController->index();
$collection = $this->response->getContent();
$this->assertContains('data', $collection);
$this->assertStringContainsString('data', $collection);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion tests/Unit/Exceptions/BadRequestExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function testRender()
$badRequestException = new BadRequestException('BAD REQUEST');
$response = $badRequestException->render();
$this->assertEquals(400, $response->getStatusCode());
$this->assertContains('BAD REQUEST', $response->getContent());
$this->assertStringContainsString('BAD REQUEST', $response->getContent());
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Exceptions/ForbiddenExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function testRender()
$forbiddenException = new ForbiddenException('FORBIDDEN');
$response = $forbiddenException->render();
$this->assertEquals(403, $response->getStatusCode());
$this->assertContains('FORBIDDEN', $response->getContent());
$this->assertStringContainsString('FORBIDDEN', $response->getContent());
}
}
2 changes: 1 addition & 1 deletion tests/Unit/Exceptions/NotFoundExceptionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ public function testRender()
$notFoundException = new NotFoundException('NOT FOUND');
$response = $notFoundException->render();
$this->assertEquals(404, $response->getStatusCode());
$this->assertContains('NOT FOUND', $response->getContent());
$this->assertStringContainsString('NOT FOUND', $response->getContent());
}
}