<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</title>
    <description>The latest articles on Forem by Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿 (@joemoses33).</description>
    <link>https://forem.com/joemoses33</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F578724%2F699b8be1-7083-4d8e-a8d5-3dafd6a02401.jpg</url>
      <title>Forem: Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</title>
      <link>https://forem.com/joemoses33</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/joemoses33"/>
    <language>en</language>
    <item>
      <title>My Start-up's tech stack.</title>
      <dc:creator>Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</dc:creator>
      <pubDate>Sun, 18 Sep 2022 00:59:08 +0000</pubDate>
      <link>https://forem.com/joemoses33/my-start-ups-tech-stack-34nh</link>
      <guid>https://forem.com/joemoses33/my-start-ups-tech-stack-34nh</guid>
      <description>&lt;p&gt;Hi there! We recently shared a post over at &lt;a href="https://assemblyapp.io/"&gt;Assembly&lt;/a&gt;, and I thought I'd share it here too - since you may find it interesting!&lt;/p&gt;

&lt;p&gt;What is the Assembly tech stack?&lt;br&gt;
Working primarily with small development agencies and technical people, we often get asked about the technology that powers the Assembly platform - and as a part of our effort to be transparent and honest, we love to share every inch of information that we can.&lt;/p&gt;

&lt;p&gt;Laravel&lt;br&gt;
Our core application logic is handled by Laravel. We’re huge fans of the Laravel Framework and the PHP language in general. By using Laravel, we can very quickly prototype, deploy and monitor new features, which is critical to our fast-moving philosophy. Thanks to the opinionated &amp;amp; standardised approach taken by Laravel, we can onboard new developers much easier than we would with a homebrew solution.&lt;/p&gt;

&lt;p&gt;Tailwind.css&lt;br&gt;
Our beautiful dashboards are styled by the utility-first library Tailwind. Tailwind is our go-to styling library for a few reasons, but the primary reason is simply how fast we can design new features and integrate them into our design library. Tailwind automatically 🌳shakes too, which means we don’t have to worry (too much) about optimizing CSS file sizes.&lt;/p&gt;

&lt;p&gt;Livewire&lt;br&gt;
Laravel Livewire utilizes over-the-wire reloading of components, handling what would be complex front-end logic in PHP, and returning rendered HTML to the user. Livewire components help us confidently ship new features and massively reduce stack complexity, effectively eliminating complicated JavaScript from our development process. Since Livewire is SSR’d, we don’t need to worry about SSR’ing JS, which is always cumbersome for the purpose of SEO.&lt;/p&gt;

&lt;p&gt;Alpine.js&lt;br&gt;
We utilize Alpine to handle simple front-end interactions that don’t qualify for an entire Livewire component. Think toggling opening and closing of menu’s, keyboard shortcuts - that kind of thing. Coming in at 7.1kB gzipped, Alpine is absolutely tiny, and packs a big punch.&lt;/p&gt;

&lt;p&gt;Github Actions&lt;br&gt;
We make use of Github actions to handle our deployment process. Effectively, our pipe looks something like this: set up PHP, install Composer, NPM, and all dependencies. Run tests, deploy code, dump caches, and reboot listeners.&lt;/p&gt;

&lt;p&gt;Digital Ocean Database Clusters&lt;br&gt;
We use MySQL-managed databases provided by DigitalOcean. We opted for DO-managed clusters to give us, and our customers peace of mind in the knowledge that all of our data is backed up, scalable, and highly available, reducing DB-based downtime to a minimum. When DO notices degraded performance or node failure, their infrastructure automatically spins up replacement nodes, keeping our platform online when it’s most important.&lt;/p&gt;

&lt;p&gt;Sentry&lt;br&gt;
We use Sentry to monitor application-level errors. When an unhandled error occurs, we are instantly notified, and provided with detailed stack traces and debugging information, to help us immediately pinpoint the error and provide resolution.&lt;/p&gt;

&lt;p&gt;Pingdom&lt;br&gt;
Using Pingdom to monitor application uptime allows us to provide public uptime status pages, which let you know when we’re having a bad day. Our team is notified when Pingdom sees something go wrong, giving us confidence that our application is online, and when it isn’t, we’ll know.&lt;/p&gt;

&lt;p&gt;Sendgrid&lt;br&gt;
Sendgrid is a fantastic tool that allows to easily send emails with high reliability, with reasonable pricing and easy integration, it’s a no-brainer for us to use their service to make sure emails arrive on time, every time.&lt;/p&gt;

&lt;p&gt;Stripe&lt;br&gt;
You guessed it, we use Stripe to handle payment and subscriptions. Why? Well, why wouldn’t you? We’re huge fans of their docs, pricing and features.&lt;/p&gt;

&lt;p&gt;Google API’s&lt;br&gt;
As you know, we provide Google Calendar integrations, for which… we use… the Google API. The Cloud Console is awesome, and pricing is pretty fair.&lt;/p&gt;

&lt;p&gt;Open Source packages&lt;br&gt;
We’d like to add a note that we’re huge fans of Open Source Software, and we extensively use OSS packages from awesome people like Spatie, jamesmills, and Guzzle.&lt;/p&gt;

&lt;p&gt;Fathom Analytics&lt;br&gt;
We care for privacy. Instead of using free services like Google Analytics, where your data, and our data is the payment, we opted to use the fantastic privacy-first Fathom Analytics, who provide fast, private and anonymous analytics.&lt;/p&gt;

&lt;p&gt;Our thoughts&lt;br&gt;
As you can hopefully tell, our stack is focused on allowing us to quickly, securely, and confidently prototype, build - and - ship new features. We like to use modern tools, and we aren’t scared of moving the stack around, previously, we did use Inertia, but we changed to Livewire - and we’re loving it.&lt;/p&gt;

</description>
      <category>startup</category>
      <category>php</category>
      <category>webdev</category>
      <category>productivity</category>
    </item>
    <item>
      <title>Create a PHP composer package | How to</title>
      <dc:creator>Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</dc:creator>
      <pubDate>Thu, 29 Jul 2021 19:29:51 +0000</pubDate>
      <link>https://forem.com/joemoses33/create-a-composer-package-how-to-29kn</link>
      <guid>https://forem.com/joemoses33/create-a-composer-package-how-to-29kn</guid>
      <description>&lt;p&gt;Composer packages are a great way of making your code available to everyone. &lt;/p&gt;

&lt;p&gt;It my be a daunting thought to create your first package, but if you break it down into simple steps, it becomes much less scary! Let's see:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Create your composer file&lt;/li&gt;
&lt;li&gt;Register your namespaces and autoloaders&lt;/li&gt;
&lt;li&gt;Write your code 🥳&lt;/li&gt;
&lt;li&gt;Push your code to your repository&lt;/li&gt;
&lt;li&gt;Create a tag or a version&lt;/li&gt;
&lt;li&gt;Submit your package to Packagist (the repo of composer packages)&lt;/li&gt;
&lt;li&gt;Done! &lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Your composer file
&lt;/h2&gt;

&lt;p&gt;Naturally, to do this, you should have composer installed. &lt;br&gt;
To check if you have composer, go ahead and run the below in your command line:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you have Composer installed, you'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;   ______
  / ____/___  ____ ___  ____  ____  ________  _____
 / /   / __ \/ __ `__ \/ __ \/ __ \/ ___/ _ \/ ___/
/ /___/ /_/ / / / / / / /_/ / /_/ (__  )  __/ /
\____/\____/_/ /_/ /_/ .___/\____/____/\___/_/
                    /_/
Composer version 2.0.4 2020-10-30 22:39:11
...
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you do not, you'll need to install &lt;a href="https://getcomposer.org/"&gt;Composer&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Now that we've got composer, we can create our Composer file. &lt;br&gt;
To get the ball rolling, just run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will begin the interactive Composer file creation. &lt;/p&gt;

&lt;p&gt;First you'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Package name (&amp;lt;vendor&amp;gt;/&amp;lt;name&amp;gt;) [pc/composer]:
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will be the name of your package Few things to note:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Vendor is the author of the package&lt;/li&gt;
&lt;li&gt;Name is the... name of the package.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Enter your name, for example I will say &lt;code&gt;joem/tutorial&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next you'll be asked for the description of your package. &lt;/p&gt;

&lt;p&gt;After that, you'll be asked for the author. &lt;/p&gt;

&lt;p&gt;You'll then be asked for the min-stability, you can skip this one, as well as &lt;code&gt;Package Type&lt;/code&gt; and &lt;code&gt;License&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You'll see:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Would you like to define your dependencies (require) interactively [yes]?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Go ahead and enter &lt;code&gt;n&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Next:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Would you like to define your dev dependencies (require-dev) interactively [yes]?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Again, a cheeky &lt;code&gt;n&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Do you confirm generation [yes]?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;yes&lt;/code&gt;!&lt;/p&gt;

&lt;p&gt;Fantastic, we've created our Composer file.&lt;/p&gt;

&lt;h2&gt;
  
  
  Project structure and namespaces
&lt;/h2&gt;

&lt;p&gt;Typically, you'll see this structure (or similar):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;project-name (root)
├── composer.json
├── composer-lock.json
├── src
│   ├── ClassName.php
│   ├── helpers.php
├── tests
│   ├── ClassNameTest.php

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note: &lt;code&gt;ClassName.php&lt;/code&gt; is the name of your class!&lt;/p&gt;

&lt;p&gt;With this in mind, we can create our autoloaders to load our files. Inside of &lt;code&gt;composer.json&lt;/code&gt;, add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="nl"&gt;"autoload"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"psr-4"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Joem\\App\\"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"src"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="nl"&gt;"files"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="s2"&gt;"src/helpers.php"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;inside of your object below &lt;code&gt;require&lt;/code&gt;. Where &lt;code&gt;Joem&lt;/code&gt; is the name of your project. Here we are autoloading all classes inside of &lt;code&gt;src&lt;/code&gt;, with the namespace of &lt;code&gt;Joem\App&lt;/code&gt;, and loading our helper file. &lt;/p&gt;

&lt;p&gt;Now, let's create our class inside of &lt;code&gt;src&lt;/code&gt;.&lt;br&gt;
Here is the example class I am using:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;
&lt;span class="kn"&gt;namespace&lt;/span&gt; &lt;span class="nn"&gt;Joem\App&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;ClassName&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;

&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the &lt;code&gt;namespace Joem\App;&lt;/code&gt;, this means it will be autoloaded into our vendor.&lt;/p&gt;

&lt;p&gt;To generate the autoloader, go head and fire:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer dump-autoload
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;into your console.&lt;/p&gt;

&lt;p&gt;This will generate an autoloader containing our class and helper file. &lt;/p&gt;

&lt;p&gt;We can now include our autoloader into our files. &lt;/p&gt;

&lt;p&gt;If we make a index.php and add:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="cp"&gt;&amp;lt;?php&lt;/span&gt;

&lt;span class="k"&gt;require_once&lt;/span&gt; &lt;span class="s1"&gt;'vendor/autoload.php'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nv"&gt;$class&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="err"&gt;\&lt;/span&gt;&lt;span class="nf"&gt;Joem\App\ClassName&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We'll see our autoloader is working!&lt;/p&gt;

&lt;p&gt;Fantastic 🥳 From here, you can add all the code you would like!&lt;/p&gt;

&lt;h2&gt;
  
  
  Git repo
&lt;/h2&gt;

&lt;p&gt;Once your class(es) are ready, we need to attach the code to a git repo, in this case, a Github repo. &lt;/p&gt;

&lt;p&gt;Once you have created you repository and added it to your codebase, you'll need a &lt;code&gt;.gitignore&lt;/code&gt; in your project root, containing &lt;code&gt;vendor/&lt;/code&gt;. This will prevent your repository from being filled with Composer dependency gunk. &lt;/p&gt;

&lt;p&gt;Your repo is important, since Packagist will use it to fetch your code. &lt;/p&gt;

&lt;p&gt;You'll need to create a release for your main branch, you can version it as &lt;code&gt;v1.0.0&lt;/code&gt;, this will prevent min-stability errors when we try to install it later!&lt;/p&gt;

&lt;h2&gt;
  
  
  Submitting the package
&lt;/h2&gt;

&lt;p&gt;We will use &lt;a href="https://packagist.org/"&gt;Packagist&lt;/a&gt; to submit our package to the Composer repository. &lt;/p&gt;

&lt;p&gt;Head to packagist and create your account.&lt;/p&gt;

&lt;p&gt;Once your account is created, click the "submit" button. You will be prompted to enter the URL of your Github repository. Once submitted, your package will be available as a Composer package!&lt;/p&gt;

&lt;p&gt;✨ A M A Z I N G ✨&lt;/p&gt;

&lt;p&gt;Now, you can install your package through composer with the command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;composer require joem/tutorial
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Where &lt;code&gt;joem/tutorial&lt;/code&gt; is the name of your package, which we inputted when we created the composer file.&lt;/p&gt;

&lt;h2&gt;
  
  
  A note on testing
&lt;/h2&gt;

&lt;p&gt;In our structure, you'll see we added a &lt;code&gt;tests&lt;/code&gt; directory, it is encouraged that your package contains tests, these can be created with a tool such as &lt;a href="https://phpunit.de/"&gt;PHPUnit&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>php</category>
      <category>opensource</category>
    </item>
    <item>
      <title>Tailwind + IntersectionObserver API = &lt;3</title>
      <dc:creator>Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</dc:creator>
      <pubDate>Sat, 08 May 2021 16:03:54 +0000</pubDate>
      <link>https://forem.com/joemoses33/tailwind-intersectionobserver-api-3-b4o</link>
      <guid>https://forem.com/joemoses33/tailwind-intersectionobserver-api-3-b4o</guid>
      <description>&lt;p&gt;The intersection observer is an incredibly powerful API, and really great for managing scrolling animations. When combined with Tailwind, it gets even better. &lt;/p&gt;

&lt;p&gt;In my use case, I have multiple elements which need to fade in once they are in the viewport, but their transition time should vary to give a sense of speed and progression.&lt;/p&gt;

&lt;p&gt;To achieve the varying animation speeds, you could do a few things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use inline styling&lt;/li&gt;
&lt;li&gt;Write a class for each element&lt;/li&gt;
&lt;li&gt;use the &lt;code&gt;attr()&lt;/code&gt; &lt;a href="https://developer.mozilla.org/en-US/docs/Learn/HTML/Howto/Use_data_attributes#css_access" rel="noopener noreferrer"&gt;method in CSS&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;My project is using Tailwind and Vue, so I opted for a tailwind class-based solution. &lt;/p&gt;

&lt;p&gt;Let's have a look at my observe:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="nf"&gt;observeHandler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;ob&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="nx"&gt;ob&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;target&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;opacity&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;ob&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;].&lt;/span&gt;&lt;span class="nx"&gt;intersectionRatio&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
      &lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="p"&gt;},&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Pretty simple stuff. We are using the intersection ratio to calculate the opacity of the element, to fade in on scroll. &lt;/p&gt;

&lt;p&gt;I've got a lot of elements to observe, here's my solution in attaching the observe:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;root&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;rootMargin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;0px&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;threshold&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.4&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.6&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.7&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.8&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mf"&gt;0.9&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;observer&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nc"&gt;IntersectionObserver&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;observeHandler&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;options&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;els&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;querySelectorAll&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;[data-observe]&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;els&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;forEach&lt;/span&gt;&lt;span class="p"&gt;((&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;observer&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;observe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;el&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Amazing, nice and simple. We seek elements with the &lt;code&gt;data-observe&lt;/code&gt; attribute:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-5xl mb-5"&lt;/span&gt; &lt;span class="na"&gt;data-observe&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Websites are more than code.&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;Now, back to our delays and transition speed. I am using Tailwind classes to manipulate those properties, here is a great example:&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;

&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex items-center delay-75"&lt;/span&gt; &lt;span class="na"&gt;data-observe&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"w-10 h-1 bg-black mr-3 mt-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-2xl"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;I capture the imagination,&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex items-center delay-300 duration-300"&lt;/span&gt; &lt;span class="na"&gt;data-observe&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"w-10 h-1 bg-black mr-3 mt-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-2xl"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;hand-craft experiences&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"flex items-center delay-500 duration-500"&lt;/span&gt; &lt;span class="na"&gt;data-observe&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"w-10 h-1 bg-black mr-3 mt-1"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"text-2xl"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;and build solutions.&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;


&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;This means I can add any number of observers, and use tailwind to control speed, which is amazing. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwpw330rl4ebhf31w0wq.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fnwpw330rl4ebhf31w0wq.gif" alt="Animation example"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;To see the final result:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://imgur.com/pdvkqjH" rel="noopener noreferrer"&gt;https://imgur.com/pdvkqjH&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>javascript</category>
      <category>tailwindcss</category>
      <category>webdev</category>
    </item>
    <item>
      <title>An accessible SVG hamburger toggle</title>
      <dc:creator>Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</dc:creator>
      <pubDate>Fri, 07 May 2021 19:08:15 +0000</pubDate>
      <link>https://forem.com/joemoses33/an-accessible-svg-hamburger-toggle-lf1</link>
      <guid>https://forem.com/joemoses33/an-accessible-svg-hamburger-toggle-lf1</guid>
      <description>&lt;p&gt;We've all been there - searching for the codepen of a navigation hamburger menu, but they never touch the spot - too much code, not accessible, messy... spending precious minutes or even &lt;em&gt;hours&lt;/em&gt; looking for the right fit.&lt;/p&gt;

&lt;p&gt;Pain, a huge pain. &lt;/p&gt;

&lt;p&gt;Finally, I've had enough! I've created an accessible SVG based navigation hamburger toggle with a fancy animation that can be dropped into your navbar with (relative) ease. &lt;/p&gt;

&lt;p&gt;I've always thought using three spans for each bar felt &lt;em&gt;wrong&lt;/em&gt;, but I've never had the time to do anything about it... until now. &lt;/p&gt;

&lt;p&gt;The link to the codepen is below - feel free to fork, change, and suggest improvements! &lt;/p&gt;

&lt;p&gt;&lt;a href="https://codepen.io/Joe45x/pen/WNpbzMR"&gt;https://codepen.io/Joe45x/pen/WNpbzMR&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Note: I'm no A11Y buff, so if the A11Y can be improved, please do share your knowledge!&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>a11y</category>
      <category>webdev</category>
    </item>
    <item>
      <title>IS PHP Dead?</title>
      <dc:creator>Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</dc:creator>
      <pubDate>Mon, 15 Feb 2021 14:56:56 +0000</pubDate>
      <link>https://forem.com/joemoses33/is-php-dead-1kgi</link>
      <guid>https://forem.com/joemoses33/is-php-dead-1kgi</guid>
      <description>&lt;p&gt;You hear it all the time - "PHP is dead", "PHP is spaghetti code", so on and so on, but is that really the case?&lt;/p&gt;

&lt;p&gt;I'm a PHP developer, who's dabbled in some backend JS too, and I try to be impartial as possible.&lt;/p&gt;

&lt;p&gt;No. The short answer is no. PHP is alive and kicking. Does that mean you should flock to it for all projects? Again, no. Should you instantly dismiss the language? No. &lt;/p&gt;

&lt;p&gt;No no no. &lt;/p&gt;

&lt;p&gt;In late 2020, PHP 8 was publicly birthed into the world, packed full of enhancements, features, improvements, and life. I get it, I truly do - older PHP was... or could be... unfortunate... we'll say. Having inherited 8-year-old codebases originally build on PHP 5.x, I know just how messy PHP can and does get - heck, even modern PHP can be written badly, but isn't that the case for near all languages?&lt;/p&gt;

&lt;p&gt;Near every language, sure, more commonly interpreted languages have room for messy code, but that doesn't mean the language itself is bad. Modern PHP can be elegant, scalable and efficient, and that's without much effort. &lt;/p&gt;

&lt;p&gt;Let's think - PHP is very much in active development. There's many, many CMS' based on PHP, and many great frameworks, too. One of the world's most popular frameworks - Laravel, is based on PHP. The world's most popular CMS - WordPress, is based on PHP. The PHP community is growing, and so is the quality of code. &lt;/p&gt;

&lt;p&gt;This doesn't mean you should swear by the language for every use-case. Sockets? Sure, PHP can do it, but should you? Are there better tools out there? Definitely.&lt;/p&gt;

&lt;p&gt;I think the problem with PHP is the low-entry barrier. PHP is great at making code just "work", which means you can, and do see a lot of poor code. That isn't always a bad thing, though. Everyone starts somewhere, right? And with the gigantic community, it's so so easy to learn and grow, which is &lt;strong&gt;incredible&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;This post is just me spewing my views. I think it's important to remain logical and to use the best languages and tools for the solution to problems. That language might be PHP, and if it is, you can write some incredible code with it - if it isn't? Great, you can do just that with any other language too. &lt;/p&gt;

&lt;p&gt;I'm very keen to hear thoughts on this topic - please do share yours :)&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>laravel</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Write good PHP - Lookup-arrays</title>
      <dc:creator>Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</dc:creator>
      <pubDate>Sun, 14 Feb 2021 18:23:57 +0000</pubDate>
      <link>https://forem.com/joemoses33/write-good-php-lookup-arrays-493a</link>
      <guid>https://forem.com/joemoses33/write-good-php-lookup-arrays-493a</guid>
      <description>&lt;p&gt;You have a list of potential values to return, dependent on a value to evaluate. A super common operation, right? You'll instantly think, chuck in an if statement, or even a switch, and call it a day - let's see an example. We want to return the relatives name based on the relation (Does anyone else forget names easily??):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'relative'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'mother'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Harriet'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'father'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Robert'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'daughter'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Rachel'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="s1"&gt;'grandmother'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Audrey'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="c1"&gt;// imagine 10 more! &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is a perfectly adequate solution: but you'd probably want to use a switch, to simplify it even further:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'relative'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;switch&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'mother'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Harriet'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'father'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Robert'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'daughter'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Rachel'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;case&lt;/span&gt; &lt;span class="s1"&gt;'grandmother'&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'Audrey'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;default&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="s1"&gt;'relative not found!'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Great, this feels much more structured, but it's quite heavy on syntax, right? Perfectly serviceable, but let's take it one step further.&lt;/p&gt;

&lt;p&gt;Enter lookup-arrays. A lookup array is a key-value paired list, where the key is what is looked up! &lt;/p&gt;

&lt;p&gt;The above, in the form of a lookup-array is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;$_GET&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s1"&gt;'relative'&lt;/span&gt;&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="nv"&gt;$relatives&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="s1"&gt;'mother'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Harriet'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'father'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Robert'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'daughter'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Rachel'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="s1"&gt;'grandmother'&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="s1"&gt;'Audrey'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
&lt;span class="p"&gt;];&lt;/span&gt;

&lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nv"&gt;$relatives&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nv"&gt;$relative&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;??&lt;/span&gt; &lt;span class="s1"&gt;'relative not found!'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can see how much easier to read a lookup-array is, and how it dramatically reduces the quantity of code, in a concise way! To note, lookup-arrays aren't always the best choice, but when they are, it should feel pretty natural!&lt;/p&gt;

&lt;p&gt;Thanks for reading - let me know your thoughts!&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Write good PHP - string management</title>
      <dc:creator>Joe 🏴󠁧󠁢󠁷󠁬󠁳󠁿</dc:creator>
      <pubDate>Sat, 13 Feb 2021 23:09:29 +0000</pubDate>
      <link>https://forem.com/joemoses33/write-good-php-string-management-4lok</link>
      <guid>https://forem.com/joemoses33/write-good-php-string-management-4lok</guid>
      <description>&lt;p&gt;Working with strings is common in any language, but it's very easy to make it harder than it needs to be! &lt;/p&gt;

&lt;p&gt;In PHP, it's very easy to work with strings, but it can be easier. &lt;/p&gt;

&lt;p&gt;Let's dissect the below example of a common, but poor usage of strings in PHP:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$firstname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'John'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$lastname&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Doe'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'The user '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$firstname&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nv"&gt;$lastname&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;' joined in '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'d/m/y'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="s1"&gt;'. Their birthday is '&lt;/span&gt; &lt;span class="mf"&gt;.&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will output exactly what you expect, but wooow, that's ugly, isn't it? Inline calculations, multiple sets of concatenation, and it's longer than it needs to be.&lt;/p&gt;

&lt;p&gt;Let's see a refactor and explain it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight php"&gt;&lt;code&gt;&lt;span class="nv"&gt;$first_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'John'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$last_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s1"&gt;'Doe'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$full_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$first_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$last_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nv"&gt;$join_date&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'d/m/y'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nv"&gt;$birthday&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;32&lt;/span&gt; &lt;span class="o"&gt;-&lt;/span&gt; &lt;span class="nb"&gt;date&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s1"&gt;'Y'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 
&lt;span class="nv"&gt;$name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;"The user &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$full_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt; joined in &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$join_date&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;. Their birthday is &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nv"&gt;$birthday&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We see more code, but it is much more readable, right? &lt;/p&gt;

&lt;p&gt;What have we done here?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;We've broken the dynamic values down to assigned variables outside of the string.&lt;/li&gt;
&lt;li&gt;We've used interpolation to avoid concatenation. Interpolation means we can avoid the dot concat syntax, and awkward strings and spaces - making the string much much easier to manage.&lt;/li&gt;
&lt;li&gt;Reduced the length of the string as a result of interpolation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Thanks to the above points, our refactor is much easier to read, and a lot easier to understand and edit. &lt;/p&gt;

&lt;p&gt;We have introduced more code, but generally, &lt;strong&gt;readability should come before length&lt;/strong&gt;. For beginners, it can be easy to fall into the trap of wanting to write really complicated code, in as few lines as possible - while cool, and very fun, it can easily get out of hand! &lt;/p&gt;

&lt;p&gt;This has been a simple example of string management in PHP, I hope you enjoyed!&lt;/p&gt;

&lt;p&gt;In the next part of this series, I'll cover writing logical structures with the happy path.&lt;/p&gt;

</description>
      <category>programming</category>
      <category>webdev</category>
      <category>php</category>
    </item>
  </channel>
</rss>
