-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[1.x] Update make:test to use PSR-4 (#482)
* Update the make:test command to use PSR-4 standards * Singularize the name
- Loading branch information
Showing
6 changed files
with
139 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
src/mantle/framework/console/generators/trait-with-psr-4-file.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
<?php | ||
/** | ||
* Has_PSR_4_Folder_Path trait file | ||
* | ||
* @package Mantle | ||
*/ | ||
|
||
namespace Mantle\Framework\Console\Generators; | ||
|
||
use function Mantle\Support\Helpers\str; | ||
|
||
/** | ||
* Generator support for PSR-4 files. | ||
* | ||
* @mixin \Mantle\Framework\Console\Generators\Generator_Command | ||
*/ | ||
trait With_PSR_4_File { | ||
/** | ||
* Get the class name to use. | ||
* | ||
* @param string $name Inputted name. | ||
* @return string | ||
*/ | ||
protected function get_class_name( string $name ): string { | ||
$name = str( str( $name )->explode( '\\' )->pop() )->studly(); | ||
|
||
if ( 'Tests' === $this->type && ! str( $name )->endsWith( 'Test' ) ) { | ||
$name = $name->append( 'Test' ); | ||
} | ||
|
||
return $name->value(); | ||
} | ||
|
||
/** | ||
* Get the folder location of the file. | ||
* | ||
* @param string $name Name to use. | ||
* @return string | ||
*/ | ||
protected function get_folder_path( string $name ): string { | ||
$parts = str( $name )->explode( '\\' ); | ||
|
||
$parts->pop(); | ||
|
||
$folder = $parts | ||
->filter() | ||
->map( fn ( string $part ) => str( $part )->studly()->value() ) | ||
->implode( DIRECTORY_SEPARATOR ); | ||
|
||
return str( $this->get_base_path() ) | ||
->append( strtolower( str_replace( '\\', '/', $this->type ) ) . DIRECTORY_SEPARATOR ) | ||
->append( $folder ) | ||
->value(); | ||
} | ||
|
||
/** | ||
* Get the location for the generated file. | ||
* | ||
* @param string $name Name to use. | ||
* @return string | ||
*/ | ||
protected function get_file_path( string $name ): string { | ||
$filename = str( | ||
str( $name )->explode( '\\' )->pop(), | ||
) | ||
->studly(); | ||
|
||
// If the type is Tests and the filename doesn't end with Test, append it. | ||
if ( 'Tests' === $this->type && ! $filename->endsWith( 'Test' ) ) { | ||
$filename = $filename->append( 'Test' ); | ||
} | ||
|
||
return str( $this->get_folder_path( $name ) ) | ||
->trailingSlash() | ||
->append( $filename->append( '.php' ) ) | ||
->value(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters