Skip to content
This repository has been archived by the owner on Aug 16, 2021. It is now read-only.

Invoice path relative to invoices_root_dir. Added invoice naming method. #5

Merged
merged 6 commits into from
Mar 1, 2018

Conversation

ambroisemaupate
Copy link
Contributor

  • Invoice path relative to invoices_root_dir in order to store only important path info in database and make it portable.
  • Added invoice naming method getInvoiceFilename which can be overridden if you want to change it.
  • Added getFilesPath getter in FileGeneratorInterface to be able to get absolute invoices folder path from controllers.

See issue #4

✌️Cheers!

@@ -19,7 +19,12 @@
/**
* @param InvoiceInterface $invoice
*
* @return string
* @return string Invoice filename
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't use PHPDoc comments

$invoice->getOrder()->getCreatedAt()->format('Ymd'),
bin2hex(random_bytes(6)),
];
return (string) implode('_', $tokens) . '.pdf';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line above the return statement


$invoice->setPath($invoicePath);
$invoiceFilename = $this->invoiceFileGenerator->generateFile($invoice);
$invoice->setPath($invoiceFilename);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a blank line above another type of algorithm operation. We separate associations, calls and input/output actions with a blank line ;)

* @param InvoiceInterface $invoice
* @return string Returns an explicit invoice file name
*/
protected function getInvoiceFilename(InvoiceInterface $invoice): string
Copy link
Member

@bitbager bitbager Feb 24, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we move it to another service? As this is a vendor plugin, I think it's worth to allow decorating/overriding this method. If this is too much for you, please change it's visibility to private, as the service is a final class and extending services in the DI app is not the best practice. Please, move it also to the bottom of the class. We're ordering methods by their visibility, so public comes above protected and private are the last ones. 🙂

//edit. I also think the method name should be generateInvoiceFilename.

$this->invoiceEntityManager->flush();
}

return $invoice->getPath();
return $this->invoiceFileGenerator->getFilesPath() . DIRECTORY_SEPARATOR . $invoice->getPath();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about we name this method getFilesDirectoryPath()? I think this will be a more clear description of the method behavior 🙂.


/**
* @param InvoiceInterface $invoice
* @return string Returns an explicit invoice file name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, add a blank line above @return doc.

.gitignore Outdated
@@ -9,3 +9,4 @@
!/etc/build/.gitkeep

/tests/Application/yarn.lock
/.idea
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, remove it from the .gitignore. Configure a global .gitignore file instead. Read more here: https://gist.github.com/subfuzion/db7f57fff2fb6998a16c

/**
* @var FilenameGeneratorInterface
*/
protected $filenameGenerator;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please, mark it as private, the class is final, so there's no need to add protected fields to it.

bitbag_sylius_invoicing_plugin.file_generator.invoice_file:
class: BitBag\SyliusInvoicingPlugin\FileGenerator\InvoicePdfFileGenerator
arguments:
- "@knp_snappy.pdf"
- "@templating"
- "@bitbag_sylius_invoicing_plugin.resolver.company_data"
- "%invoices_root_dir%"
- "@bitbag_sylius_invoicing_plugin.file_generator.invoice_filename"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In our convention, we put the object types above the default types, so if possible, interfaces over strings, arrays, etc. Could you please change this order remembering the right order in __construct call as well as properties order in InvoicePdfFileGenerator? 🙂

string $filesPath,
FilenameGeneratorInterface $filenameGenerator
FilenameGeneratorInterface $filenameGenerator,
string $filesPath
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you also change the order of declaration in __construct?

@bitbager bitbager merged commit 1a053c2 into BitBagCommerce:master Mar 1, 2018
@bitbager
Copy link
Member

bitbager commented Mar 1, 2018

Thank you @ambroisemaupate!

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

Successfully merging this pull request may close these issues.

None yet

2 participants