Skip to content

Commit

Permalink
Merge 9296738 into 10f49b2
Browse files Browse the repository at this point in the history
  • Loading branch information
crynobone committed Sep 18, 2023
2 parents 10f49b2 + 9296738 commit 5754c8b
Show file tree
Hide file tree
Showing 213 changed files with 5,242 additions and 6,355 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/analyse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ jobs:
- name: Execute Code Style Analysis
run: vendor/bin/pint --test

- name: Execute Static Code Analysis
run: vendor/bin/phpstan analyse
# - name: Execute Static Code Analysis
# run: vendor/bin/phpstan analyse
39 changes: 39 additions & 0 deletions ResourceMakeCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace Orchestra\Canvas\Tests\Feature\Console;

use Orchestra\Canvas\Tests\Feature\TestCase;

class ResourceMakeCommandTest extends TestCase
{
protected $files = [
'app/Http/Resources/FooResource.php',
'app/Http/Resources/FooResourceCollection.php',
];

/** @test */
public function it_can_generate_resource_file()
{
$this->artisan('make:resource', ['name' => 'FooResource', '--preset' => 'canvas'])
->assertSuccessful();

$this->assertFileContains([
'namespace App\Http\Resources;',
'use Illuminate\Http\Resources\Json\JsonResource;',
'class FooResource extends JsonResource',
], 'app/Http/Resources/FooResource.php');
}

/** @test */
public function it_can_generate_resource_collection_file()
{
$this->artisan('make:resource', ['name' => 'FooResourceCollection', '--collection' => true, '--preset' => 'canvas'])
->assertSuccessful();

$this->assertFileContains([
'namespace App\Http\Resources;',
'use Illuminate\Http\Resources\Json\ResourceCollection;',
'class FooResourceCollection extends ResourceCollection',
], 'app/Http/Resources/FooResourceCollection.php');
}
}
70 changes: 11 additions & 59 deletions canvas
Original file line number Diff line number Diff line change
@@ -1,67 +1,19 @@
#!/usr/bin/env php
<?php

$workingPath = getcwd();
define('CANVAS_WORKING_PATH', $workingPath = getcwd());
define('TESTBENCH_WORKING_PATH', $workingPath);

define('CANVAS_WORKING_PATH', $workingPath);
require $_composer_autoload_path ?? __DIR__.'/vendor/autoload.php';

if (file_exists(__DIR__.'/vendor/autoload.php')) {
// Development environment.
require __DIR__.'/vendor/autoload.php';
} else {
// Installation environment.
require __DIR__.'/../../autoload.php';
}

$config = ['preset' => Orchestra\Canvas\Canvas::presetFromEnvironment($workingPath)];

if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) {
$config = Symfony\Component\Yaml\Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml');
}

$files = new Illuminate\Filesystem\Filesystem();

$preset = Orchestra\Canvas\Canvas::preset(
$config, $workingPath, $files
$config = Orchestra\Testbench\Foundation\Config::loadFromYaml(
workingPath: $workingPath,
defaults: [
'providers' => [],
'dont-discover' => [],
],
);

$app = new Symfony\Component\Console\Application('Canvas for Laravel');

if (class_exists(Composer\InstalledVersions::class)) {
$app->setVersion(Composer\InstalledVersions::getPrettyVersion('orchestra/canvas'));
}

Illuminate\Support\Collection::make([
Orchestra\Canvas\Commands\Channel::class => true,
Orchestra\Canvas\Commands\Component::class => true,
Orchestra\Canvas\Commands\Console::class => true,
Orchestra\Canvas\Commands\ConsoleGenerator::class => true,
Orchestra\Canvas\Commands\Database\Cast::class => true,
Orchestra\Canvas\Commands\Database\Eloquent::class => true,
Orchestra\Canvas\Commands\Database\Factory::class => true,
Orchestra\Canvas\Commands\Database\Migration::class => true,
Orchestra\Canvas\Commands\Database\Observer::class => true,
Orchestra\Canvas\Commands\Database\Seeder::class => $preset->is('laravel'),
Orchestra\Canvas\Commands\Event::class => true,
Orchestra\Canvas\Commands\Exception::class => true,
Orchestra\Canvas\Commands\Job::class => true,
Orchestra\Canvas\Commands\Listener::class => true,
Orchestra\Canvas\Commands\Mail::class => true,
Orchestra\Canvas\Commands\Notification::class => true,
Orchestra\Canvas\Commands\Policy::class => true,
Orchestra\Canvas\Commands\Preset::class => ! file_exists("{$workingPath}/canvas.yaml"),
Orchestra\Canvas\Commands\Provider::class => true,
Orchestra\Canvas\Commands\Request::class => true,
Orchestra\Canvas\Commands\Resource::class => true,
Orchestra\Canvas\Commands\Routing\Controller::class => true,
Orchestra\Canvas\Commands\Routing\Middleware::class => true,
Orchestra\Canvas\Commands\Rule::class => true,
Orchestra\Canvas\Commands\Testing::class => true,
Orchestra\Canvas\Commands\StubPublish::class => true,
])->filter(fn ($value) => $value === true)
->keys()
->each(fn ($command) => $app->add(new $command($preset)));

$preset->addAdditionalCommands($app);
$commander = new Orchestra\Canvas\Console\Commander($config->getAttributes(), $workingPath);

$app->run();
$commander->handle();
11 changes: 6 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,21 +23,22 @@
},
"autoload-dev": {
"psr-4": {
"Orchestra\\Canvas\\Tests\\": "tests/"
"Orchestra\\Canvas\\Tests\\": "tests/",
"Illuminate\\Tests\\Integration\\Generators\\": "workbench/tests/"
}
},
"require": {
"php": "^8.0",
"illuminate/database": "^9.45",
"illuminate/support": "^9.45",
"orchestra/canvas-core": "^7.6",
"illuminate/database": "^9.52.15",
"illuminate/support": "^9.52.15",
"orchestra/canvas-core": "dev-illuminate-console",
"symfony/yaml": "^5.4 || ^6.0"
},
"require-dev": {
"laravel/framework": "^9.52.15",
"laravel/pint": "^1.4",
"mockery/mockery": "^1.5.1",
"orchestra/testbench-core": "^7.29.1",
"orchestra/testbench-core": "^7.30",
"phpstan/phpstan": "^1.10.5",
"phpunit/phpunit": "^9.5.10",
"spatie/laravel-ray": "^1.32.4"
Expand Down
16 changes: 16 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
parameters:
ignoreErrors:
-
message: "#^Unable to resolve the template type TMakeKey in call to method static method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:make\\(\\)$#"
count: 1
path: src/Console/Commander.php

-
message: "#^Unable to resolve the template type TMakeValue in call to method static method Illuminate\\\\Support\\\\Collection\\<\\(int\\|string\\),mixed\\>\\:\\:make\\(\\)$#"
count: 1
path: src/Console/Commander.php

-
message: "#^Parameter \\#1 \\$model of method Illuminate\\\\Routing\\\\Console\\\\ControllerMakeCommand\\:\\:parseModel\\(\\) expects string, array\\|bool\\|string\\|null given\\.$#"
count: 2
path: src/Console/ControllerMakeCommand.php
10 changes: 10 additions & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
@@ -1,12 +1,22 @@
includes:
- phpstan-baseline.neon

parameters:

paths:
- src

excludePaths:
- ./src/Commands/*.php
- ./src/Commands/Database/*.php
- ./src/Commands/Routing/*.php

# The level 8 is the highest level
level: 7

ignoreErrors:
- '#Method [a-zA-Z\\\<\>]+::handle\(\) should return bool\|null but returns int.#'

checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
treatPhpDocTypesAsCertain: false
54 changes: 28 additions & 26 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
<coverage includeUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Canvas Test Suite">
<directory suffix="Test.php">./tests/</directory>
</testsuite>
</testsuites>
<php>
<ini name="memory_limit" value="256M"/>
<env name="CANVAS_FOR_LARAVEL" value="(true)"/>
</php>
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
<coverage includeUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Canvas Test Suite">
<directory suffix="Test.php">tests/Feature/</directory>
<directory suffix="Test.php">tests/Unit/</directory>
<directory suffix="Test.php">workbench/tests/</directory>
</testsuite>
</testsuites>
<php>
<ini name="memory_limit" value="256M"/>
<env name="CANVAS_FOR_LARAVEL" value="(true)"/>
</php>
</phpunit>
17 changes: 8 additions & 9 deletions src/Canvas.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace Orchestra\Canvas;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;

Expand Down Expand Up @@ -37,9 +36,9 @@ public static function presetFromEnvironment(string $basePath): string
* Make Preset from configuration.
*
* @param array<string, mixed> $config
* @return \Orchestra\Canvas\Core\Presets\Preset
* @return \Orchestra\Canvas\Presets\Preset
*/
public static function preset(array $config, string $basePath, Filesystem $files): Core\Presets\Preset
public static function preset(array $config, string $basePath): Presets\Preset
{
/** @var array<string, mixed> $configuration */
$configuration = Arr::except($config, 'preset');
Expand All @@ -48,20 +47,20 @@ public static function preset(array $config, string $basePath, Filesystem $files

switch ($preset) {
case 'package':
return new Core\Presets\Package($configuration, $basePath, $files);
return new Presets\Package($configuration, $basePath);
case 'laravel':
return new Core\Presets\Laravel($configuration, $basePath, $files);
return new Presets\Laravel($configuration, $basePath);
default:
if (class_exists($preset)) {
/**
* @var class-string<\Orchestra\Canvas\Core\Presets\Preset> $preset
* @var class-string<\Orchestra\Canvas\Presets\Preset> $preset
*
* @return \Orchestra\Canvas\Core\Presets\Preset
* @return \Orchestra\Canvas\Presets\Preset
*/
return new $preset($configuration, $basePath, $files);
return new $preset($configuration, $basePath);
}

return new Core\Presets\Laravel($configuration, $basePath, $files);
return new Presets\Laravel($configuration, $basePath);
}
}
}
76 changes: 76 additions & 0 deletions src/CanvasServiceProvider.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
<?php

namespace Orchestra\Canvas;

use Illuminate\Contracts\Foundation\Application;
use Illuminate\Contracts\Support\DeferrableProvider;
use Illuminate\Support\Arr;
use Illuminate\Support\ServiceProvider;
use Orchestra\Canvas\Core\PresetManager;
use Symfony\Component\Yaml\Yaml;

class CanvasServiceProvider extends ServiceProvider implements DeferrableProvider
{
/**
* Register services.
*
* @return void
*/
public function register(): void
{
$this->callAfterResolving(PresetManager::class, function ($manager, $app) {
$manager->extend('canvas', function ($app) {
return new GeneratorPreset($app);
});

$manager->setDefaultDriver('canvas');
});

$this->app->singleton('orchestra.canvas', function (Application $app) {
$workingPath = \defined('CANVAS_WORKING_PATH') ? CANVAS_WORKING_PATH : $this->app->basePath();

$filesystem = $app->make('files');

$config = ['preset' => 'laravel'];

if (file_exists($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml')) {
$config = Yaml::parseFile($workingPath.DIRECTORY_SEPARATOR.'canvas.yaml');
} else {
Arr::set($config, 'testing.extends', [
'unit' => 'PHPUnit\Framework\TestCase',
'feature' => 'Tests\TestCase',
]);

$config['namespace'] = rescue(fn () => rtrim($this->app->getNamespace(), '\\'), null, false);
}

return Canvas::preset($config, $workingPath);
});
}

/**
* Bootstrap services.
*/
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->commands([
Console\CodeMakeCommand::class,
Console\GeneratorMakeCommand::class,
Console\PresetMakeCommand::class,
]);
}
}

/**
* Get the services provided by the provider.
*
* @return array<int, string>
*/
public function provides()
{
return [
'orchestra.canvas',
];
}
}

0 comments on commit 5754c8b

Please sign in to comment.