Skip to main content
deleted 15 characters in body
Source Link
Jamal
  • 34.9k
  • 13
  • 133
  • 237

For try catchtry/catch, statements you should ask yourself,: what are you trying to achieve? Do you need to handle the error differently in one controller compared to the rest of the application? ifIf yes, then wrap the entire contents of your method.

If no.. Laravel, Laravel implements a global error handler.. youYou simply need to throw your exceptions and laravelLaravel handles the display of the errors.

As for you unit testing, I am only learning PHPUnit at the moment but judging. Judging by your code, I believe you should take some particular emphasis on learning the S.O.L.I.D principles. https://scotchS.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-designO.L.I.D principles.

When you abide by these principles you will ensure your code is testable. To be testable your methods and objects need to have a single responsibility. E.g., such as taking requests (controller), validation (Request objects in laravel -http://laravel.com/docs/5.0/requests)Request objects in Laravel and saving data (Models).

As for Doc blocks Refer, refer to something like this. http://phpdoc2cheatsheet.com/this.

Comment you code often. For For methods I always specify in the first line a description of what the method does. (it should have a single responsibility). Then any parameters/arguments it takes (@param). Then Then any data it returns (@return). Specify the data type or 'void' if it returns nothing. Then Then finally any exceptions the method throws

I hope this helps.

For try catch statements you should ask yourself, what are you trying to achieve? Do you need to handle the error differently in one controller compared to the rest of the application? if yes then wrap the entire contents of your method.

If no.. Laravel implements a global error handler.. you simply need to throw your exceptions and laravel handles the display of the errors.

As for you unit testing, I am only learning PHPUnit at the moment but judging by your code I believe you should take some particular emphasis on learning the S.O.L.I.D principles. https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design

When you abide by these principles you will ensure your code is testable. To be testable your methods and objects need to have a single responsibility. E.g. taking requests (controller), validation (Request objects in laravel -http://laravel.com/docs/5.0/requests) and saving data (Models).

As for Doc blocks Refer to something like this. http://phpdoc2cheatsheet.com/

Comment you code often. For methods I always specify in the first line a description of what the method does. (it should have a single responsibility). Then any parameters/arguments it takes (@param). Then any data it returns (@return). Specify the data type or 'void' if it returns nothing. Then finally any exceptions the method throws

I hope this helps

For try/catch, statements you should ask yourself: what are you trying to achieve? Do you need to handle the error differently in one controller compared to the rest of the application? If yes, then wrap the entire contents of your method.

If no, Laravel implements a global error handler. You simply need to throw your exceptions and Laravel handles the display of the errors.

As for you unit testing, I am only learning PHPUnit at the moment. Judging by your code, I believe you should take some particular emphasis on learning the S.O.L.I.D principles.

When you abide by these principles you will ensure your code is testable. To be testable your methods and objects need to have a single responsibility, such as taking requests (controller), validation (Request objects in Laravel and saving data (Models).

As for Doc blocks, refer to something like this.

Comment you code often. For methods I always specify in the first line a description of what the method does. (it should have a single responsibility). Then any parameters/arguments it takes (@param). Then any data it returns (@return). Specify the data type or 'void' if it returns nothing. Then finally any exceptions the method throws.

added 34 characters in body
Source Link

For try catch statements you should ask yourself, what are you trying to achieve? Do you need to handle the error differently in one controller compared to the rest of the application? if yes then wrap the entire contents of your method.

If no.. Laravel implements a global error handler.. you simply need to throw your exceptions and laravel handles the display of the errors.

As for you unit testing, I am only learning PHPUnit at the moment but judging by your code I believe you should take some particular emphasis on learning the S.O.L.I.D principles. https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design

When you abide by these principles you will ensure your code is testable. To be testable your methods and objects need to have a single responsibility. E.g. taking requests (controller), validation (Request objects in laravel -http://laravel.com/docs/5.0/requests) and saving data (Models).

As for Doc blocks Refer to something like this. http://phpdoc2cheatsheet.com/

Comment you code often. For methods I always specify in the first line a description of what the method does. (it should have a single responsibility). Then any parameters/arguments it takes (@param). Then any data it returns (@return). Specify the data type or 'void' if it returns nothing. Then finally any exceptions the method throws

I hope this helps

For try catch statements you should ask yourself, what are you trying to achieve? Do you need to handle the error differently in one controller compared to the rest of the application? if yes then wrap the entire contents of your method.

If no.. Laravel implements a global error handler.. you simply need to throw your exceptions and laravel handles the display of the errors.

As for you unit testing, I am only learning PHPUnit at the moment but judging by your code I believe you should take some particular emphasis on learning the S.O.L.I.D principles. https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design

When you abide by these principles you will ensure your code is testable. To be testable your methods and objects need to have a single responsibility. E.g. taking requests (controller), validation (Request objects in laravel -http://laravel.com/docs/5.0/requests) and saving data (Models).

As for Doc blocks Refer to something like this. Comment you code often. For methods I always specify in the first line a description of what the method does. (it should have a single responsibility). Then any parameters/arguments it takes (@param). Then any data it returns (@return). Specify the data type or 'void' if it returns nothing. Then finally any exceptions the method throws

I hope this helps

For try catch statements you should ask yourself, what are you trying to achieve? Do you need to handle the error differently in one controller compared to the rest of the application? if yes then wrap the entire contents of your method.

If no.. Laravel implements a global error handler.. you simply need to throw your exceptions and laravel handles the display of the errors.

As for you unit testing, I am only learning PHPUnit at the moment but judging by your code I believe you should take some particular emphasis on learning the S.O.L.I.D principles. https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design

When you abide by these principles you will ensure your code is testable. To be testable your methods and objects need to have a single responsibility. E.g. taking requests (controller), validation (Request objects in laravel -http://laravel.com/docs/5.0/requests) and saving data (Models).

As for Doc blocks Refer to something like this. http://phpdoc2cheatsheet.com/

Comment you code often. For methods I always specify in the first line a description of what the method does. (it should have a single responsibility). Then any parameters/arguments it takes (@param). Then any data it returns (@return). Specify the data type or 'void' if it returns nothing. Then finally any exceptions the method throws

I hope this helps

Source Link

For try catch statements you should ask yourself, what are you trying to achieve? Do you need to handle the error differently in one controller compared to the rest of the application? if yes then wrap the entire contents of your method.

If no.. Laravel implements a global error handler.. you simply need to throw your exceptions and laravel handles the display of the errors.

As for you unit testing, I am only learning PHPUnit at the moment but judging by your code I believe you should take some particular emphasis on learning the S.O.L.I.D principles. https://scotch.io/bar-talk/s-o-l-i-d-the-first-five-principles-of-object-oriented-design

When you abide by these principles you will ensure your code is testable. To be testable your methods and objects need to have a single responsibility. E.g. taking requests (controller), validation (Request objects in laravel -http://laravel.com/docs/5.0/requests) and saving data (Models).

As for Doc blocks Refer to something like this. Comment you code often. For methods I always specify in the first line a description of what the method does. (it should have a single responsibility). Then any parameters/arguments it takes (@param). Then any data it returns (@return). Specify the data type or 'void' if it returns nothing. Then finally any exceptions the method throws

I hope this helps