New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Replace underscores with DIRECTORY_SEPARATOR (PSR-O, PSR-4) #71
Conversation
Paths that do not exist are an issue |
Fix Typo
Removed now unused directoryExists
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some small remarks left
@@ -114,6 +114,8 @@ protected function execute(InputInterface $input, OutputInterface $output) | |||
*/ | |||
protected function handleType(TypeGenerator $generator, Type $type, $path) | |||
{ | |||
// Generate type sub folders if needed | |||
$this->filesystem->ensureDirectoryExists(dirname($path)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We might want to transform $path to a SplFileInfo class so that we can avoid dirname()
* | ||
* @package PhproTest\SoapClient\Unit\CodeGenerator\Assembler | ||
*/ | ||
class TypeModelTest extends \PHPUnit_Framework_TestCase |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's better to remove this phpunit test and add the test inside the phpspec TypeSpec instead.
*/ | ||
function it_should_convert_underscores_in_path() | ||
{ | ||
$assembler = new Type('\Foo\Bar', 'Bar_3_2', []); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's not an assembler
Updated the spec test so that it also checks for the underscore replacements
@@ -17,7 +17,7 @@ class TypeSpec extends ObjectBehavior | |||
{ | |||
function let() | |||
{ | |||
$this->beConstructedWith('MyNamespace', 'myType', ['prop1' => 'string']); | |||
$this->beConstructedWith('MyNamespace', 'myType_3_2', ['prop1' => 'string']); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's probably better to use a normal type name in the normal cases but pass a different name in the path_name case
* @param string $destination | ||
* @return \SplFileInfo | ||
*/ | ||
public function getFileInfo($destination) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can specify strict types here for both parameters as return type
$path = rtrim($destination, '/\\').DIRECTORY_SEPARATOR.$this->getName().'.php'; | ||
$path = str_replace('_', DIRECTORY_SEPARATOR, $path); | ||
|
||
return new \SplFileInfo($path); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can import this as use statement
*/ | ||
public function ensureDirectoryExists($directory) | ||
public function ensureDirectoryExists(SplFileInfo $fileInfo) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since the rest of the class is using a string, we might as well keep it consistent :)
if ($this->filesystem->fileExists($path)) { | ||
if ($this->handleExistingFile($generator, $type, $path)) { | ||
if ($fileInfo->isFile()) { | ||
if ($this->handleExistingFile($generator, $type, $fileInfo->getPathname())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be a lot of work to make the command work with the splFileInfo instead of converting it to a string here?
Replace underscores in classnames with / for PSR-0 and 4 when generating a filepath.