From fc0a386cb16ee501d995f2a34c9003061803d545 Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 29 Oct 2021 19:24:25 +0200 Subject: [PATCH 1/3] Weekly thread #44 --- content/authors/SteveTheBauman.md | 5 +++++ content/authors/enunomaduro.md | 5 +++++ content/authors/freekmurze.md | 5 +++++ content/authors/jordankdalton.md | 5 +++++ content/threads/weekly-thread-2021-44.md | 8 +++++--- ...-codebase-cleaner-simpler-and-more-consistent.md | 12 ++++++++++++ ...logic-for-converting-its-instances-to-strings.md | 11 +++++++++++ ...-class-properties-directly-on-the-constructor.md | 11 +++++++++++ ...ypes1-to-enable-strict-mode-for-type-checking.md | 11 +++++++++++ ...e-gtnot-to-reverse-an-assertion-in-at-pestphp.md | 13 +++++++++++++ ...ain-and-comparing-the-value-with-the-original.md | 12 ++++++++++++ ...en-decoding-json-if-the-value-isnt-valid-json.md | 11 +++++++++++ 12 files changed, 106 insertions(+), 3 deletions(-) create mode 100644 content/authors/SteveTheBauman.md create mode 100644 content/authors/enunomaduro.md create mode 100644 content/authors/freekmurze.md create mode 100644 content/authors/jordankdalton.md create mode 100644 content/tips/create-traits-for-relationships-you-commonly-use-in-your-models-to-make-your-codebase-cleaner-simpler-and-more-consistent.md create mode 100644 content/tips/implement-the-tostring-method-in-a-class-to-specify-custom-logic-for-converting-its-instances-to-strings.md create mode 100644 content/tips/use-constructor-property-promotion-to-define-class-properties-directly-on-the-constructor.md create mode 100644 content/tips/use-declarestrict-types1-to-enable-strict-mode-for-type-checking.md create mode 100644 content/tips/use-gtnot-to-reverse-an-assertion-in-at-pestphp.md create mode 100644 content/tips/you-can-check-if-a-string-contains-json-by-decoding-it-encoding-it-again-and-comparing-the-value-with-the-original.md create mode 100644 content/tips/you-can-make-php-throw-an-exception-when-decoding-json-if-the-value-isnt-valid-json.md diff --git a/content/authors/SteveTheBauman.md b/content/authors/SteveTheBauman.md new file mode 100644 index 0000000..041287a --- /dev/null +++ b/content/authors/SteveTheBauman.md @@ -0,0 +1,5 @@ +--- +username: SteveTheBauman +name: 'Steve Bauman' +avatar: 'https://pbs.twimg.com/profile_images/1447680179560751115/8Wm9RSco_normal.jpg' +--- diff --git a/content/authors/enunomaduro.md b/content/authors/enunomaduro.md new file mode 100644 index 0000000..eff057d --- /dev/null +++ b/content/authors/enunomaduro.md @@ -0,0 +1,5 @@ +--- +username: enunomaduro +name: 'Nuno Maduro' +avatar: 'https://pbs.twimg.com/profile_images/1433501939648565257/hT4oXpfq_normal.jpg' +--- diff --git a/content/authors/freekmurze.md b/content/authors/freekmurze.md new file mode 100644 index 0000000..ea4797c --- /dev/null +++ b/content/authors/freekmurze.md @@ -0,0 +1,5 @@ +--- +username: freekmurze +name: 'Freek Van der Herten 🔭' +avatar: 'https://pbs.twimg.com/profile_images/1433390470965735424/f5UiMISj_normal.jpg' +--- diff --git a/content/authors/jordankdalton.md b/content/authors/jordankdalton.md new file mode 100644 index 0000000..5bcaec0 --- /dev/null +++ b/content/authors/jordankdalton.md @@ -0,0 +1,5 @@ +--- +username: jordankdalton +name: 'Jordan Dalton' +avatar: 'https://pbs.twimg.com/profile_images/1408944806517161986/KtHWdoeI_normal.jpg' +--- diff --git a/content/threads/weekly-thread-2021-44.md b/content/threads/weekly-thread-2021-44.md index 8d69f3a..ad6f5e7 100644 --- a/content/threads/weekly-thread-2021-44.md +++ b/content/threads/weekly-thread-2021-44.md @@ -1,9 +1,11 @@ --- slug: weekly-thread-2021-44 title: 'Weekly thread #44 of 2021' -tweet_id: '1451526348132978689' +tweet_id: '1454133799164522500' author_username: archtechx -created_at: 2021-10-24T11:19:00+00:00 +created_at: 2021-10-29T17:17:04+00:00 links: { } --- -🔥 This week’s code tips for Laravel developers \ No newline at end of file +🔥 This week's code tips for Laravel developers + +Lots of cool stuff from @enunomaduro and two competing JSON tips 💪 \ No newline at end of file diff --git a/content/tips/create-traits-for-relationships-you-commonly-use-in-your-models-to-make-your-codebase-cleaner-simpler-and-more-consistent.md b/content/tips/create-traits-for-relationships-you-commonly-use-in-your-models-to-make-your-codebase-cleaner-simpler-and-more-consistent.md new file mode 100644 index 0000000..b0adbbb --- /dev/null +++ b/content/tips/create-traits-for-relationships-you-commonly-use-in-your-models-to-make-your-codebase-cleaner-simpler-and-more-consistent.md @@ -0,0 +1,12 @@ +--- +title: 'Create traits for relationships you commonly use in your models to make your codebase cleaner, simpler, and more consistent ✨' +tweet_id: '1454133823210459140' +thread_slug: weekly-thread-2021-44 +author_username: jordankdalton +images: + - 'https://pbs.twimg.com/media/FCZiei8WYAA_mZQ.jpg' + - 'https://pbs.twimg.com/media/FCZiei7XIAEgVSm.jpg' +created_at: 2021-10-29T17:11:34+00:00 +slug: create-traits-for-relationships-you-commonly-use-in-your-models-to-make-your-codebase-cleaner-simpler-and-more-consistent +--- +Laravel Tip: Abstract relations you commonly use to a trait. It’s a DRY approach that keeps your models thin. \ No newline at end of file diff --git a/content/tips/implement-the-tostring-method-in-a-class-to-specify-custom-logic-for-converting-its-instances-to-strings.md b/content/tips/implement-the-tostring-method-in-a-class-to-specify-custom-logic-for-converting-its-instances-to-strings.md new file mode 100644 index 0000000..88e85cc --- /dev/null +++ b/content/tips/implement-the-tostring-method-in-a-class-to-specify-custom-logic-for-converting-its-instances-to-strings.md @@ -0,0 +1,11 @@ +--- +title: 'Implement the __toString() method in a class to specify custom logic for converting its instances to strings' +tweet_id: '1454133805745385473' +thread_slug: weekly-thread-2021-44 +author_username: enunomaduro +images: + - 'https://pbs.twimg.com/media/FCx22U5WQAYOWi4.jpg' +created_at: 2021-10-29T17:11:30+00:00 +slug: implement-the-tostring-method-in-a-class-to-specify-custom-logic-for-converting-its-instances-to-strings +--- +PHP reminder: you can use the method "__toString()" to specify the string representation of an object. ✅ \ No newline at end of file diff --git a/content/tips/use-constructor-property-promotion-to-define-class-properties-directly-on-the-constructor.md b/content/tips/use-constructor-property-promotion-to-define-class-properties-directly-on-the-constructor.md new file mode 100644 index 0000000..bd3b5ba --- /dev/null +++ b/content/tips/use-constructor-property-promotion-to-define-class-properties-directly-on-the-constructor.md @@ -0,0 +1,11 @@ +--- +title: 'Use constructor property promotion to define class properties directly on the constructor' +tweet_id: '1454133812863152128' +thread_slug: weekly-thread-2021-44 +author_username: enunomaduro +images: + - 'https://pbs.twimg.com/media/FCdTrpMX0AAid3y.jpg' +created_at: 2021-10-29T17:11:32+00:00 +slug: use-constructor-property-promotion-to-define-class-properties-directly-on-the-constructor +--- +PHP reminder: you can define your class properties directly on the constructor. ✅ \ No newline at end of file diff --git a/content/tips/use-declarestrict-types1-to-enable-strict-mode-for-type-checking.md b/content/tips/use-declarestrict-types1-to-enable-strict-mode-for-type-checking.md new file mode 100644 index 0000000..f82d13d --- /dev/null +++ b/content/tips/use-declarestrict-types1-to-enable-strict-mode-for-type-checking.md @@ -0,0 +1,11 @@ +--- +title: 'Use declare(strict_types=1) to enable strict mode for type checking' +tweet_id: '1454133808786202627' +thread_slug: weekly-thread-2021-44 +author_username: enunomaduro +images: + - 'https://pbs.twimg.com/media/FCiPA0kWUAUoban.jpg' +created_at: 2021-10-29T17:11:31+00:00 +slug: use-declarestrict-types1-to-enable-strict-mode-for-type-checking +--- +PHP reminder: The "declare(strict_types = 1);" directive enables strict mode. In strict mode, only a variable of exact type of the “type declaration” will be accepted, or a "TypeError" will be thrown. ✅ \ No newline at end of file diff --git a/content/tips/use-gtnot-to-reverse-an-assertion-in-at-pestphp.md b/content/tips/use-gtnot-to-reverse-an-assertion-in-at-pestphp.md new file mode 100644 index 0000000..9c2a8a6 --- /dev/null +++ b/content/tips/use-gtnot-to-reverse-an-assertion-in-at-pestphp.md @@ -0,0 +1,13 @@ +--- +title: 'Use ->not to reverse an assertion in @pestphp ' +tweet_id: '1454133816990240773' +thread_slug: weekly-thread-2021-44 +author_username: enunomaduro +images: + - 'https://pbs.twimg.com/media/FCtnhAvXEAco-Kc.jpg' +created_at: 2021-10-29T17:11:33+00:00 +slug: use-gtnot-to-reverse-an-assertion-in-at-pestphp +--- +Pest reminder: if you know how to test something, "not()" lets you test its opposite. ✅ + +https://pestphp.com/docs/expectations#expect-not \ No newline at end of file diff --git a/content/tips/you-can-check-if-a-string-contains-json-by-decoding-it-encoding-it-again-and-comparing-the-value-with-the-original.md b/content/tips/you-can-check-if-a-string-contains-json-by-decoding-it-encoding-it-again-and-comparing-the-value-with-the-original.md new file mode 100644 index 0000000..7562858 --- /dev/null +++ b/content/tips/you-can-check-if-a-string-contains-json-by-decoding-it-encoding-it-again-and-comparing-the-value-with-the-original.md @@ -0,0 +1,12 @@ +--- +title: 'You can check if a string contains JSON by decoding it, encoding it again, and comparing the value with the original' +tweet_id: '1454133800888410119' +thread_slug: weekly-thread-2021-44 +author_username: freekmurze +images: + - 'https://pbs.twimg.com/media/FC4Bs0lXEA4WV-P.jpg' +created_at: 2021-10-29T17:11:29+00:00 +slug: you-can-check-if-a-string-contains-json-by-decoding-it-encoding-it-again-and-comparing-the-value-with-the-original +--- +🔥 A way to check if a string contains valid JSON: just decode it, encode it again, and check if it matches the original value +#php \ No newline at end of file diff --git a/content/tips/you-can-make-php-throw-an-exception-when-decoding-json-if-the-value-isnt-valid-json.md b/content/tips/you-can-make-php-throw-an-exception-when-decoding-json-if-the-value-isnt-valid-json.md new file mode 100644 index 0000000..ca3dbc3 --- /dev/null +++ b/content/tips/you-can-make-php-throw-an-exception-when-decoding-json-if-the-value-isnt-valid-json.md @@ -0,0 +1,11 @@ +--- +title: 'You can make PHP throw an exception when decoding JSON if the value isn''t valid JSON' +tweet_id: '1454133803056775178' +thread_slug: weekly-thread-2021-44 +author_username: SteveTheBauman +images: + - 'https://pbs.twimg.com/media/FCuqk2zWQAsk08o.jpg' +created_at: 2021-10-29T17:11:29+00:00 +slug: you-can-make-php-throw-an-exception-when-decoding-json-if-the-value-isnt-valid-json +--- +Had no idea you could have PHP throw a built-in exception when decoding JSON -- I've always done this manually until today 😭 \ No newline at end of file From 3f0320b2443e8dabf8b095cf60cf2ad7f725cdbd Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 29 Oct 2021 19:33:24 +0200 Subject: [PATCH 2/3] Fix -> symbol in tip title, slug and file name --- ... use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md} | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) rename content/tips/{use-gtnot-to-reverse-an-assertion-in-at-pestphp.md => use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md} (64%) diff --git a/content/tips/use-gtnot-to-reverse-an-assertion-in-at-pestphp.md b/content/tips/use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md similarity index 64% rename from content/tips/use-gtnot-to-reverse-an-assertion-in-at-pestphp.md rename to content/tips/use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md index 9c2a8a6..778dd2e 100644 --- a/content/tips/use-gtnot-to-reverse-an-assertion-in-at-pestphp.md +++ b/content/tips/use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md @@ -1,13 +1,13 @@ --- -title: 'Use ->not to reverse an assertion in @pestphp ' +title: 'Use ->not to reverse an assertion in @pestphp ' tweet_id: '1454133816990240773' thread_slug: weekly-thread-2021-44 author_username: enunomaduro images: - 'https://pbs.twimg.com/media/FCtnhAvXEAco-Kc.jpg' created_at: 2021-10-29T17:11:33+00:00 -slug: use-gtnot-to-reverse-an-assertion-in-at-pestphp +slug: use-arrow-not-to-reverse-an-assertion-in-at-pestphp --- Pest reminder: if you know how to test something, "not()" lets you test its opposite. ✅ -https://pestphp.com/docs/expectations#expect-not \ No newline at end of file +https://pestphp.com/docs/expectations#expect-not From c9c29a0787d6cb32e11f39bd0c99510c088af83e Mon Sep 17 00:00:00 2001 From: lukinovec Date: Fri, 29 Oct 2021 20:17:06 +0200 Subject: [PATCH 3/3] Remove 'arrow' from slug and file name --- ...tphp.md => use-not-to-reverse-an-assertion-in-at-pestphp.md} | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename content/tips/{use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md => use-not-to-reverse-an-assertion-in-at-pestphp.md} (87%) diff --git a/content/tips/use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md b/content/tips/use-not-to-reverse-an-assertion-in-at-pestphp.md similarity index 87% rename from content/tips/use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md rename to content/tips/use-not-to-reverse-an-assertion-in-at-pestphp.md index 778dd2e..92c8448 100644 --- a/content/tips/use-arrow-not-to-reverse-an-assertion-in-at-pestphp.md +++ b/content/tips/use-not-to-reverse-an-assertion-in-at-pestphp.md @@ -6,7 +6,7 @@ author_username: enunomaduro images: - 'https://pbs.twimg.com/media/FCtnhAvXEAco-Kc.jpg' created_at: 2021-10-29T17:11:33+00:00 -slug: use-arrow-not-to-reverse-an-assertion-in-at-pestphp +slug: use-not-to-reverse-an-assertion-in-at-pestphp --- Pest reminder: if you know how to test something, "not()" lets you test its opposite. ✅