This file contains hidden or 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
| class OrderManager { | |
| public createOrder(orderData) { | |
| (new OrderValidator).validateOrderInput(orderData); | |
| const total = (new OrderCalculator).calculateTotal(orderData); | |
| (new MyPaymentGateway).processPayment(total, { meta: "info" }); | |
| return (new OrderRepository()).save(orderData); | |
| } | |
| } |
This file contains hidden or 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
| class OrderManager { | |
| public async createOrder(orderData) { | |
| if (!orderData.items.length) { | |
| throw new ValidationError("Cannot create an order: cart is empty"); | |
| } | |
| orderData.items.forEach((orderItem) => { | |
| if (orderItem.productId === undefined || orderItem.quantity === undefined || orderItem.price === undefined) { | |
| throw new ValidationError("Cannot create an order: product ID is missing"); | |
| } |
This file contains hidden or 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
| <?php | |
| // be sure to change BaseUser to inherit from Permitable | |
| Yii::import('application.components.behaviors.ActiveRecordOriginalAttributeValuesBehavior'); | |
| Yii::import('application.components.behaviors.VendoriTimestampBehavior'); | |
| use vendori\components\clearbit\RequestQueuedException; | |
| use Phpass\Hash as PhpassHash; | |
| use vendori\components\ClearbitSalesReps; | |
| use vendori\emails\RegistrationConfirmation; |
This file contains hidden or 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
| <?php | |
| class Yii1Model | |
| { | |
| public function rules() | |
| { | |
| // NOTE: you should only define rules for those attributes that | |
| // will receive user inputs. | |
| return array( | |
| // Required fields |
This file contains hidden or 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
| class DailyAttendanceReport { | |
| public constructor( | |
| private reportGenerator: DailyAttendanceReportGenerator, | |
| private reportSender: DailyAttendanceReportSender | |
| ) {} | |
| public generate = () => { | |
| const report = this.reportGenerator.generate(); | |
| this.reportSender.send(report); | |
| }; |
This file contains hidden or 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
| class DailyAttendanceReport { | |
| public constructor( | |
| private knex: Knex, | |
| private viewRenderer: ViewRenderer, | |
| private emailTransport: EmailTransport | |
| ) {} | |
| public generate = () => { | |
| const since = moment() | |
| .subtract(1, "days") |
This file contains hidden or 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
| class RoastedDuckReceipt { | |
| public cook() { | |
| console.log("Prepare the duck"); | |
| console.log("Add spices"); | |
| console.log("Roast the duck for 3 hours"); | |
| console.log("Make a sauce"); | |
| } | |
| } | |
| class CeasarSaladReceipt { |
This file contains hidden or 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
| class Cook { | |
| public makeDinner() { | |
| this.cookRoastedDuck(); | |
| this.cookCeasarSalad(); | |
| this.serveDrinks(); | |
| } | |
| private cookRoastedDuck() { | |
| console.log("Prepare the duck"); | |
| console.log("Add spices"); |
This file contains hidden or 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
| class Cook { | |
| public makeDinner() { | |
| console.log("Dinner served"); | |
| } | |
| } | |
| const mom = new Cook(); | |
| mom.makeDinner(); |
This file contains hidden or 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
| const di: IDIContainer = configureTestDI(); | |
| const knex = di.get<Knex>(APP_DEP.DB); | |
| const dbSeeder = di.get<DbSeeder>(APP_DEP.TEST_DB_SEEDER); | |
| const repo = new PostsRepo(knex); | |
| describe("PostsRepo", () => { | |
| // to speed up our tests and do not trash test DB | |
| // we will run test in the transaction and roll it back after execution | |
| beforeEach(async () => { | |
| await knex.raw("BEGIN"); |