Skip to content
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

Merged
merged 6 commits into from Sep 29, 2017

Conversation

janvernieuwe
Copy link
Member

Replace underscores in classnames with / for PSR-0 and 4 when generating a filepath.

@janvernieuwe
Copy link
Member Author

janvernieuwe commented Sep 22, 2017

Paths that do not exist are an issue
edit: Fixed

Removed now unused directoryExists
@veewee veewee added this to the 0.5.3 milestone Sep 29, 2017
Copy link
Contributor

@veewee veewee left a 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));
Copy link
Contributor

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
Copy link
Contributor

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', []);
Copy link
Contributor

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']);
Copy link
Contributor

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)
Copy link
Contributor

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);
Copy link
Contributor

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)
Copy link
Contributor

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())) {
Copy link
Contributor

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants