Skip to content

Commit

Permalink
Merge pull request #61 from ajthinking/avoid-str-macros
Browse files Browse the repository at this point in the history
Avoid str macros
  • Loading branch information
ajthinking authored Mar 9, 2022
2 parents 6bc48f3 + 5aeefaa commit 9ffd7c1
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 85 deletions.
7 changes: 3 additions & 4 deletions src/Endpoints/Laravel/BelongsTo.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
namespace Archetype\Endpoints\Laravel;

use Archetype\Endpoints\EndpointProvider;
use Archetype\Support\LaravelStrings;
use Archetype\Support\Snippet;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;
use PhpParser\BuilderFactory;

class BelongsTo extends EndpointProvider
{
Expand All @@ -26,9 +25,9 @@ protected function add($targets)
->insertStmts(
collect(Arr::wrap($targets))->map(function ($target) {
return Snippet::___BELONGS_TO_METHOD___([
'___BELONGS_TO_METHOD___' => Str::belongsToMethodName($target),
'___BELONGS_TO_METHOD___' => LaravelStrings::belongsToMethodName($target),
'___TARGET_CLASS___' => class_basename($target),
'___TARGET_IN_DOC_BLOCK___' => Str::belongsToDocBlockName($target)
'___TARGET_IN_DOC_BLOCK___' => LaravelStrings::belongsToDocBlockName($target)
]);
})->toArray()
)->commit()
Expand Down
6 changes: 3 additions & 3 deletions src/Endpoints/Laravel/BelongsToMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Archetype\Endpoints\Laravel;

use Archetype\Endpoints\EndpointProvider;
use Archetype\Support\LaravelStrings;
use Archetype\Support\Snippet;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;

class BelongsToMany extends EndpointProvider
Expand All @@ -25,9 +25,9 @@ protected function add($targets)
->insertStmts(
collect(Arr::wrap($targets))->map(function ($target) {
return Snippet::___BELONGS_TO_MANY_METHOD___([
'___BELONGS_TO_MANY_METHOD___' => Str::belongsToManyMethodName($target),
'___BELONGS_TO_MANY_METHOD___' => LaravelStrings::belongsToManyMethodName($target),
'___TARGET_CLASS___' => class_basename($target),
'___TARGET_IN_DOC_BLOCK___' => Str::belongsToManyDocBlockName($target)
'___TARGET_IN_DOC_BLOCK___' => LaravelStrings::belongsToManyDocBlockName($target)
]);
})->toArray()
)->commit()
Expand Down
6 changes: 3 additions & 3 deletions src/Endpoints/Laravel/HasMany.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
namespace Archetype\Endpoints\Laravel;

use Archetype\Endpoints\EndpointProvider;
use Archetype\Support\LaravelStrings;
use Archetype\Support\Snippet;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;

class HasMany extends EndpointProvider
Expand All @@ -25,9 +25,9 @@ protected function add($targets)
->insertStmts(
collect(Arr::wrap($targets))->map(function ($target) {
return Snippet::___HAS_MANY_METHOD___([
'___HAS_MANY_METHOD___' => Str::hasManyMethodName($target),
'___HAS_MANY_METHOD___' => LaravelStrings::hasManyMethodName($target),
'___TARGET_CLASS___' => class_basename($target),
'___TARGET_IN_DOC_BLOCK___' => Str::hasManyDocBlockName($target)
'___TARGET_IN_DOC_BLOCK___' => LaravelStrings::hasManyDocBlockName($target)
]);
})->toArray()
)->commit()
Expand Down
7 changes: 3 additions & 4 deletions src/Endpoints/Laravel/HasOne.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace Archetype\Endpoints\Laravel;

use Archetype\Endpoints\EndpointProvider;
use Archetype\Support\LaravelStrings;
use Archetype\Support\Snippet;
use Illuminate\Support\Str;
use Illuminate\Support\Arr;

class HasOne extends EndpointProvider
{
Expand All @@ -25,9 +24,9 @@ protected function add($targets)
->insertStmts(
collect($targets)->map(function ($target) {
return Snippet::___HAS_ONE_METHOD___([
'___HAS_ONE_METHOD___' => Str::hasOneMethodName($target),
'___HAS_ONE_METHOD___' => LaravelStrings::hasOneMethodName($target),
'___TARGET_CLASS___' => class_basename($target),
'___TARGET_IN_DOC_BLOCK___' => Str::hasOneDocBlockName($target)
'___TARGET_IN_DOC_BLOCK___' => LaravelStrings::hasOneDocBlockName($target)
]);
})->toArray()
)->commit()
Expand Down
4 changes: 0 additions & 4 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,9 @@
use Archetype\Commands\ErrorsCommand;
use Archetype\Factories\LaravelFileFactory;
use Archetype\Factories\PHPFileFactory;
use Archetype\Traits\AddsLaravelStringsToStrWithMacros;

class ServiceProvider extends BaseServiceProvider
{
use AddsLaravelStringsToStrWithMacros;

public function register()
{
$this->registerFacades();
Expand All @@ -22,7 +19,6 @@ public function register()

public function boot()
{
$this->bootStrMacros();
$this->publishConfig();
}

Expand Down
72 changes: 72 additions & 0 deletions src/Support/LaravelStrings.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Archetype\Support;

use Illuminate\Support\Str;

class LaravelStrings
{
public static function hasOneMethodName($target)
{
return Str::camel(
class_basename($target)
);
}

public static function hasManyMethodName($target)
{
return Str::camel(
Str::plural(
class_basename($target)
)
);
}

public static function belongsToMethodName($target)
{
return Str::camel(
class_basename($target)
);
}

public static function belongsToManyMethodName($target)
{
return Str::camel(
Str::plural(
class_basename($target)
)
);
}

public static function hasOneDocBlockName($target)
{
return Str::studly(
class_basename($target)
);
}

public static function hasManyDocBlockName($target)
{
return Str::studly(
Str::plural(
class_basename($target)
)
);
}

public static function belongsToDocBlockName($target)
{
return Str::studly(
class_basename($target)
);
}

public static function belongsToManyDocBlockName($target)
{
return Str::studly(
Str::plural(
class_basename($target)
)
);
}
}
67 changes: 0 additions & 67 deletions src/Traits/AddsLaravelStringsToStrWithMacros.php

This file was deleted.

0 comments on commit 9ffd7c1

Please sign in to comment.