<?xml version='1.0' encoding='UTF-8'?>
<rss version='2.0'>
<channel>
<title>Todd Eidson's Programming Blog</title>
<link>https://eidson.info</link>
<description>Programming Blog</description>
<language>en-us</language><item>
<title>Fancy Up Your Fonts with Ligatures</title>
<link>https://eidson.info/post/fancy-fonts</link>
<description>&lt;p&gt;&lt;img src=&quot;/img/fancy-fonts.png&quot; alt=&quot;not equals ligatures&quot; title=&quot;not equals ligatures&quot; /&gt;&lt;/p&gt;
&lt;h1&gt;Fancy Up Your Fonts with Ligatures&lt;/h1&gt;
&lt;h2&gt;&amp;quot;Woah, how&apos;d you get your not equals to look like that?&amp;quot;&lt;/h2&gt;
&lt;p&gt;I&apos;ve recently started a new job and am now taking part in regular code reviews. The majority of these reviews take place over a video chat in which screen sharing is used in conjunction with Intellij&apos;s &amp;quot;Git &amp;gt; Compare with branch&amp;quot; to display the diff.  We then talk through the changes and raise any concerns with the changes.&lt;/p&gt;
&lt;p&gt;On several occasions, usually mid-sentence, I get the question &amp;quot;Woah, how&apos;d you get your not equals to look like that?&amp;quot; Or equals, or greater-than-or-equal-to, or lambda operator, or ... the list goes on.&lt;/p&gt;
&lt;p&gt;&amp;quot;Oh, that? That&apos;s a ligature, you can turn that on easily in your Intellij settings.&amp;quot;&lt;/p&gt;
&lt;p&gt;I&apos;ve had &apos;ligatures&apos; in my &amp;quot;blog ideas&amp;quot; list for well over a year, so I&apos;ve decided to go ahead and scratch that one off the list.&lt;/p&gt;
&lt;h2&gt;What are Ligatures?&lt;/h2&gt;
&lt;p&gt;According to &lt;a href=&quot;https://www.fonts.com/content/learning/fontology/level-3/signs-and-symbols/ligatures-1&quot;&gt;fonts.com&lt;/a&gt; a ligature is &amp;quot;a special character that combines two (or sometimes three) characters into a single character.&amp;quot;&lt;/p&gt;
&lt;p&gt;Ligatures aren&apos;t available in most font sets. I first discovered them in &lt;a href=&quot;https://github.com/tonsky/FiraCode&quot;&gt;Fira Code&lt;/a&gt;, when I was looking for a new monospace font to use for programming. It was one of those happy little accidents where I stumbled across something that I never knew I needed to solve a problem that I didn&apos;t even know I had. I had to try them out right away. And I fell in love with ligatures instantly. Ligatures make code look much cleaner, and scan much more quickly, in my opinion.&lt;/p&gt;
&lt;p&gt;This is an image borrowed from the &lt;a href=&quot;https://github.com/tonsky/FiraCode&quot;&gt;Fira Code&lt;/a&gt; repo displaying how all of the ligatures look.&lt;/p&gt;
&lt;img src=&quot;https://raw.githubusercontent.com/tonsky/FiraCode/master/showcases/all_ligatures.png&quot; width=&quot;100%&quot;&gt;
&lt;h3&gt;Fira Code Alternatives&lt;/h3&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://github.com/i-tu/Hasklig&quot;&gt;Haskilig&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://larsenwork.com/monoid/&quot;&gt;Monoid&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://github.com/SSNikolaevich/DejaVuSansCode&quot;&gt;Deja Vu Sans Code&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://rubjo.github.io/victor-mono/&quot;&gt;Victor Mono&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://typeof.net/Iosevka/&quot;&gt;Iosevka&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Enabling Ligatures in Intellij&lt;/h2&gt;
&lt;p&gt;Okay, you&apos;re convinced. Ligatures are great and you want to start using them immediately. So how do you do that?&lt;/p&gt;
&lt;p&gt;To enable ligatures in Intellij (or any other Jetbrains IDE), the first thing to do is to open up settings (alt+ctrl+s on Linux/Windows or ⌘ + comma on Mac).&lt;/p&gt;
&lt;p&gt;Then you can go to &amp;quot;Editor &amp;gt; Font&amp;quot; or start typing &amp;quot;ligatures&amp;quot; in the search input.&lt;/p&gt;
&lt;p&gt;All that&apos;s left now is to select &amp;quot;Fira Code&amp;quot; or another font that includes ligatures and check the &amp;quot;Enable font ligatures&amp;quot; checkbox. (Fira Code is included with all of the newer Jetbrains IDEs, you may have to install any other fonts you want to try)&lt;/p&gt;
&lt;img src=&quot;/img/ligatures.png&quot; width=&quot;50%&quot;&gt;
&lt;h2&gt;Other IDEs&lt;/h2&gt;
&lt;p&gt;In addition to the Jetbrains IDEs, you can also enable ligatures in most other popular IDEs, code editors, and some terminals.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Atom&lt;/li&gt;
&lt;li&gt;Eclipse&lt;/li&gt;
&lt;li&gt;Netbeans&lt;/li&gt;
&lt;li&gt;Notepad++&lt;/li&gt;
&lt;li&gt;Sublime Text&lt;/li&gt;
&lt;li&gt;Visual Studio&lt;/li&gt;
&lt;li&gt;Visual Studio Code&lt;/li&gt;
&lt;li&gt;iTerm 2&lt;/li&gt;
&lt;li&gt;Kitty&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Also, I just learned while researching this post, you can import the CSS and use ligatures in most modern browsers!&lt;/p&gt;
&lt;p&gt;So what are you waiting for? Fire up your favorite IDE and start playing with ligatures today!&lt;/p&gt;
</description>
<pubDate>Sun, 19 Jan 2020 00:00:00 UTC</pubDate>
</item><item>
<title>Face Value</title>
<link>https://eidson.info/post/face-value</link>
<description>&lt;p&gt;&lt;img src=&quot;/img/face-value.jpg&quot; alt=&quot;playing cards&quot; title=&quot;playing cards&quot; /&gt;&lt;/p&gt;
&lt;h1&gt;Face Value&lt;/h1&gt;
&lt;p&gt;I&apos;d recently been on a job hunt (now fulfilled), and I was contacted through stackoverflow by a recruiter that had located my stackoverflow Developer&apos;s Story and was impressed.  He&apos;d asked me to complete a coding challenge which I passed with flying colors. I was then invited to participate in a technical interview with one of their team leaders and a developer - this is where the trouble began.&lt;/p&gt;
&lt;p&gt;The first problem was that recruiter had informed me that this interview was to go over my code sample and take a deeper dig into my background; so I wasn&apos;t expecting a full-blown technical interview and therefore had failed to do any preparation.&lt;/p&gt;
&lt;p&gt;The second problem is that I&apos;d never taken part in a &amp;quot;real&amp;quot; technical interview and as such as I wasn&apos;t sure what to expect. I had, of course, read articles in the past about technical interviews, but it had been quite some time. It would have behooved me to reread some articles to have a better idea of what to expect.&lt;/p&gt;
&lt;p&gt;So problems one and two are closely related and boil down to a lack of preparation and experience. It is my insight garnered from the third strike that I would like to share with you today: take all interview questions at face value.&lt;/p&gt;
&lt;p&gt;The job posting for this position had a salary range that, to me, was &amp;quot;crazy&amp;quot; money. Imposing a sense of imposter syndrome from the get-go, so the very first question caught me off guard.&lt;/p&gt;
&lt;p&gt;&amp;quot;How would you model a deck of playing cards? What members would you use and what methods would you need to make available?&amp;quot;&lt;/p&gt;
&lt;p&gt;Simple, right? A deck of cards is simply an array of cards, each card having a suit and a value. However, I had the thought, &amp;quot;this question cannot be this simple, can it? There has to be a trick. What&apos;s the catch?&amp;quot;&lt;/p&gt;
&lt;p&gt;So instead of giving the simple answer, I stuttered and stammered, trying to buy time to process the question from other angles. I had entered a state of analysis paralysis. I was overthinking the problem to the nth degree. Instead of giving the simple (and correct) answer, I tried to make my answer as complicated as my perceived (and unreal) impression of the question. I was seeing a hidden meaning behind the question that just was not there. I did not take the question at its face value.&lt;/p&gt;
&lt;p&gt;This was only the first question, and I was crashing and burning, HARD. They let me flounder for about ten minutes before stopping me and moving on to the next question. No, that&apos;s not fair. They didn&apos;t let me flounder. They tried to steer me towards the right answer. They even went so far as to &amp;quot;rephrase&amp;quot; my answer back to me to make it sound like I had given the right answer. I was not having that, so I stuck to my guns; I &amp;quot;corrected&amp;quot; them - to make sure that they knew that I had given the wrong answer. They were great. Kudos to them for not calling me an idiot.&lt;/p&gt;
&lt;p&gt;I did manage to recover, for the most part, and partially redeem myself for the rest of the interview. At least to the point that I am pretty sure that they don&apos;t think someone else wrote my sample project.&lt;/p&gt;
&lt;p&gt;Several days later, I received the nicest rejection email that I have ever received.  The recruiter encouraged me to try again in the future and wished me the best of luck on my future endeavors.&lt;/p&gt;
&lt;p&gt;All in all, even though I was kicking myself in the butt for the next 48 hours, it was a positive experience. I got some valuable interview experience, for one. A couple of hours later, I fired up IntelliJ and modeled a deck of playing cards, properly - in an attempt to strengthen my Java knowledge in preparation for another interview I had coming up. I did land that position, which I felt was a much better fit for me, anyway. Also, most importantly, I learned, the hard way, to always take an interview question at face value.&lt;/p&gt;
&lt;div class=&quot;level__item&quot;&gt;
&lt;div class=&quot;js-copy-attribute-content rd__p rd__p--no-margin&quot;&gt;Photo by &lt;strong&gt;
          &lt;a href=&quot;https://www.pexels.com/@ken123films?utm_content=attributionCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=pexels&quot;&gt;
            kendall hoopes
          &lt;/a&gt;
        &lt;/strong&gt; from &lt;strong&gt;
          &lt;a href=&quot;https://www.pexels.com/photo/close-up-photo-of-playing-cards-1796794/?utm_content=attributionCopyText&amp;amp;utm_medium=referral&amp;amp;utm_source=pexels&quot;&gt;
            Pexels
          &lt;/a&gt;
        &lt;/strong&gt;&lt;/div&gt;
&lt;/div&gt;
&lt;br&gt;
</description>
<pubDate>Sat, 28 Sep 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Catching Mail with MailCatcher</title>
<link>https://eidson.info/post/catching-mail-with-mailcatcher</link>
<description>&lt;p&gt;&lt;img src=&quot;/img/mail.webp&quot; alt=&quot;&quot; title=&quot;mailboxes&quot; /&gt;&lt;/p&gt;
&lt;h1&gt;Catching Mail with MailCatcher&lt;/h1&gt;
&lt;h2&gt;MailCatcher&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://mailcatcher.me/&quot;&gt;MailCatcher&lt;/a&gt; is a powerful and easy to use Ruby gem that acts as an SMTP server that allows you to inspect emails that your application is sending out in your dev environment.&lt;/p&gt;
&lt;h3&gt;Installation&lt;/h3&gt;
&lt;p&gt;Installation is pretty simple, these are the commands that I used on my Fedora 29 install to get it up and running.  If Ruby is already installed on your machine, or if you&apos;ve already installed other Ruby gems, you may not need the first few lines.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;sudo dnf install ruby
sudo dnf group install &amp;quot;C Development Tools and Libraries&amp;quot;
sudo dnf install ruby-devel zlib-devel

# Redhat-rpm-config and libsqlite3x-devel are the mailcatcher specific requirements
sudo dnf install redhat-rpm-config libsqlite3x-devel
gem install mailcatcher
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After everything installs properly, from a terminal run MailCatcher.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;mailcatcher
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;MailCatcher has options that you can pass it if you need to change the SMTP port or the port the web front end uses, these can be viewed by running &lt;code&gt;mailcatcher --help&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Now that MailCatcher is up and running, we&apos;re ready to send it some e-mail.&lt;/p&gt;
&lt;h2&gt;Symfony&lt;/h2&gt;
&lt;p&gt;The default &lt;code&gt;MAILER_URL&lt;/code&gt; is NULL in a Symfony project, which is rational setting that ensures that you aren&apos;t sending out emails while running a project in the dev environment (which I&apos;ve done, on more than one occasion).  However, there are occasions when you want to verify that an e-mail is being sent or you want to inspect the contents of that email.  Symfony, of course, does provide &lt;a href=&quot;https://symfony.com/doc/current/email/dev_environment.html&quot;&gt;ways&lt;/a&gt; through the Web Debug Toolbar to view the contents of sent e-mail and to override the intended recipient, so you aren&apos;t spamming users with dev emails (but you have to check the header if you want to see who the intended recipient was).  However, I find that using MailCatcher has a more developer friendly UI and requires less configuration.&lt;/p&gt;
&lt;p&gt;In your Symfony &lt;code&gt;.env&lt;/code&gt; file change the &lt;code&gt;MAILER_URL&lt;/code&gt; to point to the instance of MailCatcher.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# .env file
MAILER_URL=smtp://localhost:1025
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now all that is left to do is to point a browser to &lt;a href=&quot;http://127.0.0.1:1080/&quot;&gt;http://127.0.0.1:1080/&lt;/a&gt; to see any emails that are sent from your Symfony project.&lt;/p&gt;
&lt;p&gt;Of course, one other benefit of using MailCatcher over the built-in Symfony tools for catching dev emails is that you aren&apos;t limited to using this for just Symfony projects. You can drop this in anywhere that has a configurable SMTP url setting.&lt;/p&gt;
</description>
<pubDate>Sun, 31 Mar 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Uses</title>
<link>https://eidson.info/post/uses</link>
<description>&lt;p&gt;&lt;img src=&quot;/img/IMG_1784.jpg&quot; alt=&quot;&quot; title=&quot;View&quot; /&gt;&lt;/p&gt;
&lt;h1&gt;Uses&lt;/h1&gt;
&lt;p&gt;Inspired years ago by &lt;a href=&quot;https://www.hanselman.com/blog/ScottHanselmans2014UltimateDeveloperAndPowerUsersToolListForWindows.aspxi&quot;&gt;Scott Hanselman&apos;s tool list&lt;/a&gt; and more recently by &lt;a href=&quot;https://wesbos.com/uses/&quot;&gt;Wes Bos&apos; uses&lt;/a&gt; and prodded into action so I could make a pull request to the &lt;a href=&quot;https://github.com/wesbos/awesome-uses&quot;&gt;awesome-uses&lt;/a&gt; repo by Wes Bos, here is a list of the tools that I use on a daily basis:&lt;/p&gt;
&lt;h2&gt;Operating System&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://getfedora.org/&quot;&gt;Fedora&lt;/a&gt; -  currently using version 29. I&apos;ve been using different flavors of Linux off and on since 2009, but after switching to Fedora (26?) in November of 2017 from Win10 both at work and at home, I haven&apos;t looked back since...&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;IDE&apos;s/Code Editors&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://www.jetbrains.com/phpstorm/&quot;&gt;PhpStorm&lt;/a&gt; - This is my go-to workhorse IDE - amazing to work in, not a single feature that I can think of that is missing.  In fact, I have ALL of the JetBrain&apos;s IDE&apos;s on my work machine thanks to their Toolbox Subscription model, absolute best bang for your buck, IMO.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://code.visualstudio.com/&quot;&gt;Visual Studio Code&lt;/a&gt; - I pull this one out when I don&apos;t need all the features of PhpStorm and want to use something a little lighter.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://www.sublimetext.com/3&quot;&gt;Sublime Text 3&lt;/a&gt; - Because a carpenter needs to have more than one type of hammer in their bag, and be proficient in using them.  This is another great lightweight code editor that still gets lots of use.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://www.eclipse.org/birt/about/designer.php&quot;&gt;Eclipse BIRT Report Designer&lt;/a&gt; - I use this one reluctantly at work when I need to write a database report.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Terminals&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/Guake/guake&quot;&gt;Guake&lt;/a&gt; - I love the f12 hotkey to bring this up, so fast to fire off a quick terminal command&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://gnometerminator.blogspot.com/p/introduction.html&quot;&gt;Terminator&lt;/a&gt; - If I want a more persistent terminal docked beside another window, I&apos;ll fire up Terminator&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;File Comparator&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://www.scootersoftware.com/&quot;&gt;Beyond Compare&lt;/a&gt; - Nothing beats the features of Beyond Compare for file/directory comparison.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;http://meldmerge.org/&quot;&gt;meld&lt;/a&gt; - Is a great free alternative&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;SQL Tools&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://www.jetbrains.com/datagrip/&quot;&gt;DataGrip&lt;/a&gt; - Another great tool from Jetbrains. I&apos;m still finding a new neat feature almost daily.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://heidisql.com&quot;&gt;HeidiSQL&lt;/a&gt; - I use HeidiSQL via wine to address a couple areas that DataGrip is lacking in:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Copying tables with or without data to a new database - I copy a lot of tables from prod to dev to develop with real data, or sometimes, I&apos;ll copy a table from dev/test to prod when I am implementing a new feature.  DataGrip has implemented this recently, but it is still no where as nice as using HeidiSQL&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Creating VIEWs - this is another area where HeidiSQL beats DataGrip hands down&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Notes&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://www.notion.so/&quot;&gt;notion&lt;/a&gt; - I&apos;d tried lots of other apps to keep notes in and nothing comes close to the power of notion.  I&apos;ve only scratched the surface of its flexibility, but it is still amazingly useful even only using the bare-bones features.&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;Hardware&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Razer Black Widow Ultimate 2013 Keyboard - I wanted a mechanical keyboard with lighting and this one filled the bill.  I liked it so much that I ran out and bought a second one for work after only using it at home for a week.  They&apos;ve served me well for almost 6 years now, but I am tempted by the sexiness of the &lt;a href=&quot;http://www.wasdkeyboards.com/index.php/products/code-keyboard.html&quot;&gt;wasd CODE keyboard&lt;/a&gt;.  I might pick up one as a present to myself someday soon.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;&lt;a href=&quot;https://www.amazon.com/gp/product/B06XWDJZLF/ref=ppx_yo_dt_b_asin_title_o08_s00?ie=UTF8&amp;amp;psc=1&quot;&gt;Sleekform Ergonomic Adjustable Office Desk Chair&lt;/a&gt; - I lost my Herman Miller Aeron chair in a break up, so I replaced it with this much more affordable knock off from Amazon.  It&apos;s just as comfortable and durable as the Aeron, and assembly was much easier.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img src=&quot;/img/IMG_1788.jpg&quot; width=&quot;50%&quot;&gt;
&lt;h2&gt;Music&lt;/h2&gt;
&lt;p&gt;I couldn&apos;t last a day in my office or home office without some music...&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;p&gt;Thorens TD-166 MkII Turntable - They made everything better in the 1970s (including me) - This was my Father&apos;s Day present to myself several years ago.&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Kenwood KA-8006 Solid State Stereo Integrated Amplifier - Just look at all those real knobs and switches... and it sounds great, too!&lt;/p&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;p&gt;KLH AV-44 Speakers - The only part of my system made this century, but I&apos;ll give them a pass.  They still can keep up with my vintage gear.&lt;/p&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;img src=&quot;/img/IMG_1787.jpg&quot; width=&quot;40%&quot; style=&quot;float: left; margin: 30px;&quot;&gt;
&lt;img src=&quot;/img/IMG_1786.jpg&quot; width=&quot;40%&quot; style=&quot;margin: 30px;&quot;&gt;
&lt;br&gt;
</description>
<pubDate>Sat, 23 Mar 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Using Conventional Commit Messages - Globally</title>
<link>https://eidson.info/post/using-conventional-commit-messages-globally</link>
<description>&lt;p&gt;&lt;img src=&quot;/img/git-logo.png&quot; alt=&quot;&quot; title=&quot;git logo&quot; /&gt;&lt;/p&gt;
&lt;h1&gt;Automating Conventional Commit Messages - Globally&lt;/h1&gt;
&lt;p&gt;I am constantly on the lookout for ways to better myself as a developer. This includes not only getting better at the actual art of coding but also improving the processes of coding and finding ways to streamline and/or automate these processes. One of the areas that I had already (mostly) improved on is writing useful commit messages, so my &lt;code&gt;git log&lt;/code&gt; doesn&apos;t end up looking like this XKCD comic:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;https://imgs.xkcd.com/comics/git_commit.png&quot; alt=&quot;&quot; title=&quot;XKCD Commit Comic&quot; /&gt;&lt;/p&gt;
&lt;p&gt;One bad habit that is easy to fall into as a solo developer (especially under a time constraint) is to rationalize ignoring or delaying proper documentation since you&apos;re the only one working in the codebase it is easy to think that documentation is unimportant. And it is. Until it isn&apos;t - and then it is &lt;em&gt;really&lt;/em&gt; important.&lt;/p&gt;
&lt;p&gt;So that is one area that I am constantly trying to improve in. A git commit message is an oft-overlooked and undervalued form of documentation, so how can we improve here?  I had already been, for the most part, following &lt;a href=&quot;https://chris.beams.io/posts/git-commit/#seven-rules&quot;&gt;The seven rules of a great Git commit message&lt;/a&gt;. They made sense and were easy enough to implement, and almost got me to where I wanted to be as far as git commit messages were concerned.&lt;/p&gt;
&lt;p&gt;However, I was recently made aware of the &lt;a href=&quot;https://www.conventionalcommits.org/&quot;&gt;Conventional Commits&lt;/a&gt; standard published by the Angular Team thanks to the &lt;a href=&quot;https://dev.to/maxpou/enhance-your-git-log-with-conventional-commits-3ea4&quot;&gt;Enhance your git log with conventional commits&lt;/a&gt; post on &lt;a href=&quot;https://dev.to&quot;&gt;dev.to&lt;/a&gt;. I really liked the article and the standard so I bookmarked it for a more thorough reading.  It was a couple of days later when I went back to the post and saw the following &lt;a href=&quot;https://dev.to/joelnet/comment/9be2&quot;&gt;comment&lt;/a&gt; that really got my wheels spinning:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;a href=&quot;https://dev.to/joelnet&quot;&gt;JavaScript Joel&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;I have added husky + commitizen + commitlint to our projects and it has been great.&lt;/p&gt;
&lt;p&gt;Some benefits include an auto-generated change log. auto-incrementing semantic versioning. and increased visibility for breaking changes.&lt;/p&gt;
&lt;p&gt;I would recommend it for every project.&lt;/p&gt;
&lt;p&gt;Because we are using gitlab, we are using these packages semantic-release-gitlab and npm-publish-git-tag.&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;So I got to googling and found the &lt;a href=&quot;https://dev.bleacherreport.com/how-we-use-commitizen-to-clean-up-commit-messages-a16790dcd2fd&quot;&gt;How We Use Commitizen to Clean Up Commit Messages&lt;/a&gt; post that I used for a starting point on implementing and enforcing conventional commit messages.&lt;/p&gt;
&lt;p&gt;The only problem was that the vast majority of my projects are PHP projects, and these are all npm packages. As much as I wanted to add this to my workflow, I wasn&apos;t keen on the idea of adding a &lt;code&gt;package.json&lt;/code&gt; file to each project and adding unnecessary complexity to my dev process. So I went about discovering if these tools could be added globally so they could be added to my ~30 projects without configuring them individually for each project.&lt;/p&gt;
&lt;h2&gt;The Tools&lt;/h2&gt;
&lt;p&gt;There were three tools that I had to configure:&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href=&quot;https://github.com/commitizen/cz-cli&quot;&gt;commitizen&lt;/a&gt;- Help write the conventional commit message&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://github.com/conventional-changelog/commitlint&quot;&gt;commitlint&lt;/a&gt; - Determine if the commit message is properly formatted&lt;/li&gt;
&lt;li&gt;
&lt;a href=&quot;https://eidson.info/post/global-hooks-with-git&quot;&gt;git global hooks&lt;/a&gt; - Fail the commit if the commit message is not properly formatted&lt;/li&gt;
&lt;/ul&gt;
&lt;h3&gt;Commitizen&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/commitizen/cz-cli&quot;&gt;commitizen&lt;/a&gt; is a handy little command line utility that provides prompts and hints for filling out each section for a conventional commit message.&lt;/p&gt;
&lt;p&gt;The first step is to install it using npm:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install -g commitizen
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Install your preferred commitizen adapter globally, for example cz-conventional-changelog&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install -g cz-conventional-changelog
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a .czrc file in your home directory, with path referring to the preferred, globally installed, commitizen adapter&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;echo &apos;{ &amp;quot;path&amp;quot;: &amp;quot;cz-conventional-changelog&amp;quot; }&apos; &amp;gt; ~/.czrc
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After commitizen has been installed, instead of making a commit with &lt;code&gt;git commit&lt;/code&gt; you make a commit with:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git cz
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This launches commitzen and you&apos;ll be prompted to first select the type of commit you are making:&lt;/p&gt;
&lt;img src=&quot;/img/commitizen_1.png&quot; width=&quot;100%&quot;&gt;
&lt;br&gt;
&lt;p&gt;After the type of commit is selected, you&apos;ll be prompted to fill out the subject, body, breaking changes, and open issues sections:&lt;/p&gt;
&lt;img src=&quot;/img/commitizen_2.png&quot; width=&quot;100%&quot;&gt;
&lt;br&gt;
&lt;div class=&quot;card&quot;&gt;
&lt;h5 class=&quot;card-header&quot;&gt;Pro-tip:&lt;/h5&gt;
&lt;div class=&quot;card-body&quot;&gt;
For the body (`Provide a longer description of the change:`)
&lt;br&gt;
 If you want to add newlines you can add them with the `\n` newline character.
&lt;pre&gt;
 &lt;code class=&quot;language-bash hijs&quot;&gt;
 Does a thing that is important\n\nBy doing\n-Thing 1\n-Thing 2
 &lt;/code&gt;
&lt;/pre&gt;
The dashes create a bullet list.&lt;br&gt;
&lt;br&gt;
Yes, this is an ugly work around, but the only way that I found that works, and not a deal breaker, for me.
&lt;/div&gt;
&lt;/div&gt;
Now that commitizen is installed and working, we can move on to the next step.
&lt;h2&gt;Commitlint&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/conventional-changelog/commitlint&quot;&gt;commitlint&lt;/a&gt; is a tool that will lint your commit message and let you know if it adheres to whatever standard you&apos;ve chosen.&lt;/p&gt;
&lt;p&gt;Global installation is as easy as commitizen, but it is not explained in the readme.  I had to dig around in the github issues to find an example. I plan on making a pull request to remedy this, but here are the steps:&lt;/p&gt;
&lt;p&gt;Install the cli utility and the configuration you wish to apply:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;npm install -g @commitlint/cli @commitlint/config-conventional
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Create a global config file:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;echo &amp;quot;module.exports = {extends: [&apos;@commitlint/config-conventional&apos;]}&amp;quot; &amp;gt; ~/commitlint.config.js
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;That is all there to it.  You can test that it is installed and working by running the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;echo &apos;should fail&apos; | commitlint
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And to see a passing message you can try:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;echo &amp;quot;fix(server): send cors headers&amp;quot; | commitlint
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now we&apos;re ready to tie it all together...&lt;/p&gt;
&lt;h2&gt;git hook&lt;/h2&gt;
&lt;p&gt;commitlint in and of itself does not really do much until it is placed into a git hook. It is from inside this hook that we can fail the commit if the message does not follow the standard.&lt;/p&gt;
&lt;p&gt;Like the earlier npm packages, I wanted this applied to all of my projects, without configuring a git hook for each individual project.  If you are unfamiliar with using git hooks globally, you can check out my previous post on &lt;a href=&quot;https://eidson.info/post/global-hooks-with-git&quot;&gt;git global hooks&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;If you&apos;ve got global git hooks configured already, you can add a file as &lt;code&gt;/path/to/global/hooks/commit-msg&lt;/code&gt;.  I use the fish shell for my scripting, but the bash shouldn&apos;t look too much different.  The line &lt;code&gt;commitlint &amp;lt; $argv[1]&lt;/code&gt; does the work, I think bash would be &lt;code&gt;commitlint &amp;lt; $1&lt;/code&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;#! /usr/bin/fish

# run any local commit-msg hook first
if test -e ./.git/hooks/commit-msg
        sh ./.git/hooks/commit-msg
end

commitlint &amp;lt; $argv[1]

exit $status
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;In Conclusion&lt;/h2&gt;
&lt;p&gt;So there you have it, three easy steps to set up a conventional commit message workflow. This is most useful if you can get in the habit of making &lt;a href=&quot;https://seesparkbox.com/foundry/atomic_commits_with_git&quot;&gt;atomic commits&lt;/a&gt;.  You can see the real beauty of this after making a few commits and then running &lt;code&gt;git log --one-line&lt;/code&gt;.  Give it a shot and see what you think!&lt;/p&gt;
</description>
<pubDate>Sun, 17 Mar 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Unit Testing PHP Dates and Times with Carbon</title>
<link>https://eidson.info/post/unit-testing-dates-and-times-with-carbon</link>
<description>&lt;p&gt;&lt;img src=&quot;/img/php.png&quot; alt=&quot;php logo&quot; title=&quot;php logo&quot; /&gt;&lt;/p&gt;
&lt;h1&gt;Unit Testing Dates and Times with Carbon&lt;/h1&gt;
&lt;p&gt;One area of my codebase at work that I had problems sufficiently testing were instances in my code base that had time based logic to them.  Since I work in the manufacturing sector, lots of logic relies on knowing what the current, last, or next shift is. There are lots of edge cases that need tested around shift change, especially third shift, which starts before midnight, but for all the reporting and other facets of my software it is technically tomorrow.&lt;/p&gt;
&lt;p&gt;So these time-dependant functions for the most part did not have useful, functional unit tests, until recently.  In the past I would write my logic, cross my fingers and wait for the bug reports to come rolling in.  I&apos;m so thankful that I discovered this testing aid built in to the &lt;a href=&quot;https://carbon.nesbot.com/docs/#api-testing&quot;&gt;Carbon&lt;/a&gt; PHP library.  (If you haven&apos;t used Carbon, stop reading and go check it out, I&apos;ll forgive you.  It makes working with dates and times in PHP a walk in the park, it is one of the most useful libraries I use!)&lt;/p&gt;
&lt;p&gt;So now you are wondering, &amp;quot;What is this wonderful function that will let me test my date/time based logic easier?&amp;quot; I&apos;m glad you asked. It is the &lt;code&gt;setTestNow()&lt;/code&gt; function built in to the &lt;a href=&quot;https://carbon.nesbot.com/docs/#api-testing&quot;&gt;Carbon&lt;/a&gt; api.  Basically, this allows you to determine when &lt;code&gt;now()&lt;/code&gt; is.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;// instantiate a carbon object equal to &apos;2019-01-06 23:15:00)
$testDate = Carbon::create(2019, 1, 6, 23, 15);
Carbon::setTestNow($testDate);

$date = new Carbon();
// $date = &apos;2019-01-06 23:15:00&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The great thing is that this &lt;code&gt;now()&lt;/code&gt; persists across other classes, allowing easy time-based unit testing.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&amp;lt;?php

namespace Tests;

use App\Shift;
use Carbon\Carbon;
use PHPUnit\Framework\TestCase;

class ShiftTimesTest extends TestCase
{
    public function testThirdShift()
    {
        $testDate = Carbon::create(2019, 3, 8, 23, 15);
        Carbon::setTestNow($testDate);
        $shift = new Shift();

        $this-&amp;gt;assertEquals(3, $shift-&amp;gt;getCurrent());
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Discovering this helper has allowed me to add tests to lots of previously untested areas of the code base, and allowed me to get away from PDD (Prayer Driven Development).&lt;/p&gt;
</description>
<pubDate>Sat, 09 Mar 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Creating an RSS Feed for a Symfony Blog</title>
<link>https://eidson.info/post/creating-an-rss-feed-for-a-symfony-blog</link>
<description>&lt;h1&gt;Creating an RSS Feed for a Symfony Blog&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/symfony_black_02.png&quot; alt=&quot;&quot; title=&quot;Symfony Logo&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;One of the features I&apos;ve wanted to add to this blog for a while now, but kept putting off, until now, is an RSS feed.  I recently created an account on &lt;a href=&quot;https://connect.symfony.com&quot;&gt;connect.symfony.com&lt;/a&gt; and there was a spot to add an RSS feed to one&apos;s profile, which was the only thing stopping me from getting my profile to 100% and earning the &amp;quot;Profile completed&amp;quot; badge.  Nothing like a little gamification to make me stop putting off this task.&lt;/p&gt;
&lt;p&gt;Since I&apos;m never one to re-invent the wheel, without justification, I of course looked to see if there were any Symfony bundles that would allow me to easily add an RSS feed to my blog.  &amp;quot;Easily&amp;quot; being the keyword in that sentence.  I did find several of bundles, but all of them seemed to have convoluted configuration, with a learning curve much steeper than rolling my own.&lt;/p&gt;
&lt;p&gt;Oh, yea, you can see it in action here: https://eidson.info/rss&lt;/p&gt;
&lt;h2&gt;Rolling My Own&lt;/h2&gt;
&lt;p&gt;So, with a mission in hand I headed over to my google machine.  The first handful of hits showed an implementation using PHP&apos;s XMLWriter, which is probably the &apos;right&apos; way to do it, and would have been the better choice, if the XMl I needed to generate was any more complex than it was, but it seemed like overkill for such a simple string.  Luckily, I stumbled across a post on &lt;a href=&quot;http://talkerscode.com/webtricks/create-rss-feed-using-php.php&quot;&gt;talkerscode&lt;/a&gt; which gave me a good starting point.&lt;/p&gt;
&lt;h3&gt;Generating the XML&lt;/h3&gt;
&lt;p&gt;The first class that I created was a class to create my xml string that I wanted to return as my response (shown below).  It is basically a simple static function that takes an array of posts and creates a properly formatted XMl string creating an &lt;code&gt;item&lt;/code&gt; element for each post.  When I tried to run this, the first couple of posts were handled properly, and then it choked and died.  It turns out that the title of one of my post&apos;s contained an ampersand (&apos;&amp;amp;&apos;), which is not handled correctly by an xml parser, So I created a little helper function to escape any characters that were going to through the XML parsers for a loop.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&amp;lt;?php

namespace AppBundle\Rss;

class Xml
{
    public static function generate($posts)
    {
        $xml = &amp;lt;&amp;lt;&amp;lt;xml
&amp;lt;?xml version=&apos;1.0&apos; encoding=&apos;UTF-8&apos;?&amp;gt;
&amp;lt;rss version=&apos;2.0&apos;&amp;gt;
&amp;lt;channel&amp;gt;
&amp;lt;title&amp;gt;Todd Eidson&apos;s Programming Blog&amp;lt;/title&amp;gt;
&amp;lt;link&amp;gt;https://eidson.info&amp;lt;/link&amp;gt;
&amp;lt;description&amp;gt;Programming Blog&amp;lt;/description&amp;gt;
&amp;lt;language&amp;gt;en-us&amp;lt;/language&amp;gt;
xml;
        foreach ($posts as $post) {

            $title = self::xmlEscape($post-&amp;gt;getTitle());
            $url = self::xmlEscape($post-&amp;gt;getUrl());
            $slug = self::xmlEscape($post-&amp;gt;getHtml());
            $pubDate = $post-&amp;gt;getPublished()-&amp;gt;format(&apos;D, d M Y H:i:s T&apos;);
            $xml .= &amp;lt;&amp;lt;&amp;lt;xml
&amp;lt;item&amp;gt;
&amp;lt;title&amp;gt;{$title}&amp;lt;/title&amp;gt;
&amp;lt;link&amp;gt;https://eidson.info/post/{$url}&amp;lt;/link&amp;gt;
&amp;lt;description&amp;gt;{$slug}&amp;lt;/description&amp;gt;
&amp;lt;pubDate&amp;gt;$pubDate&amp;lt;/pubDate&amp;gt;
&amp;lt;/item&amp;gt;
xml;
        }
        $xml .= &amp;quot;&amp;lt;/channel&amp;gt;&amp;lt;/rss&amp;gt;&amp;quot;;

        return $xml;
    }

    private static function xmlEscape($string) {
        return str_replace(array(&apos;&amp;amp;&apos;, &apos;&amp;lt;&apos;, &apos;&amp;gt;&apos;, &apos;\&apos;&apos;, &apos;&amp;quot;&apos;), array(&apos;&amp;amp;amp;&apos;, &apos;&amp;amp;lt;&apos;, &apos;&amp;amp;gt;&apos;, &apos;&amp;amp;apos;&apos;, &apos;&amp;amp;quot;&apos;), $string);
    }
}

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Creating a Controller&lt;/h3&gt;
&lt;p&gt;So now that I had the XML generation working smoothly, I needed a way to handle an incoming request and return the appropriate response, which consists of the &lt;code&gt;Content-Type: text/xml;&lt;/code&gt; header and the XML string.  So I was able to create a Symfony controller that fetched the posts, created a response, set the headers, added the XML content, and returned the response.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&amp;lt;?php
namespace AppBundle\Controller;

use AppBundle\Rss\Xml;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;

class RssController extends Controller
{
    /**
     * @Route(&amp;quot;/rss&amp;quot;, name=&amp;quot;rss-feed&amp;quot;)
     *
     * @return \Symfony\Component\HttpFoundation\Response
     */
    public function rssAction()
    {
        $posts = $this-&amp;gt;getDoctrine()
            -&amp;gt;getRepository(&apos;AppBundle:Post&apos;)
            -&amp;gt;fetch();

        $response = new Response();
        $response-&amp;gt;headers-&amp;gt;set(&amp;quot;Content-type&amp;quot;, &amp;quot;text/xml&amp;quot;);
        $response-&amp;gt;setContent(Xml::generate($posts));
        return $response;

    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Now I had my rss feed up and running, I was able to get my &lt;a href=&quot;https://connect.symfony.com&quot;&gt;connect.symfony.com&lt;/a&gt; profile to 100%, earn a badge, and scratch &amp;quot;create an RSS feed&amp;quot; off of my to-do list.  There are a couple improvements that could be made.  When I get more than 15 or 20 posts, I&apos;ll probably limit the response to the last 10 or so posts, and if I ever start to get a lot of traffic, I&apos;ll probably cache the XML and only update it when a new post is added, but remember kids, &amp;quot;premature optimization is the root of all evil&amp;quot;!&lt;/p&gt;
&lt;p&gt;Thanks for reading.  Feedback and/or questions are always appreciated!&lt;/p&gt;
</description>
<pubDate>Sun, 03 Mar 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Override a trait in PHP</title>
<link>https://eidson.info/post/ovveride-a-trait-in-php</link>
<description>&lt;h1&gt;Override a trait in PHP&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/php.png&quot; alt=&quot;php logo&quot; title=&quot;php logo&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I encountered a situation recently in which I wanted to change the method signature for a method that was injected into a class via a trait, namely changing the default parameter.  I wanted to do this so I didn&apos;t have to pass in the new default parameter every place that I called this method on this particular class.&lt;/p&gt;
&lt;p&gt;Overriding the method, was easy enough.  As soon as a new method is declared in a class with the same name, the trait method is overridden.  The tricky part was calling the &apos;parent&apos; method from the &apos;child&apos; method, so I didn&apos;t have to duplicate the logic inside my new method.  I tried &lt;code&gt;parent::methodName()&lt;/code&gt; and &lt;code&gt;TraitName::methodName()&lt;/code&gt; before running off to the google machine to learn the proper way to do this.&lt;/p&gt;
&lt;p&gt;It turns out that it is as easy as creating an alias for the trait method name in the &amp;quot;Use&amp;quot; statement, which made perfect sense after I saw it.&lt;/p&gt;
&lt;p&gt;So, if this is the trait that you want to use and override:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;trait SomeTrait {
    public function someMethod(string $key = &apos;Id&apos;)
    {
        // logic
        return $resultOfLogic;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Just give an alias to the trait method name when &amp;quot;Using&amp;quot; the trait as such:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;use SomeTrait {someMethod as public traitSomeMethod;}&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Here is a full example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;&amp;lt;?php

class Something
{
    use SomeTrait {someMethod as public traitSomeMethod;}

    public function someMethod(string $key = &apos;Name&apos;)
    {
        return $this-&amp;gt;traitSomeMethod($key);
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So now I could call this method on any instantiation of this class without explicitly passing the default &lt;code&gt;$key&lt;/code&gt; every time I needed to call it.  Also, I had the added benefit of not having to duplicate the logic, keeping things DRY and ensuring that any changes made to the traits logic would &apos;bubble down&apos; to the concrete implementation of the class.&lt;/p&gt;
</description>
<pubDate>Sat, 23 Feb 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Global Hooks with git</title>
<link>https://eidson.info/post/global-hooks-with-git</link>
<description>&lt;h1&gt;Global Hooks with Git&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/git-logo.png&quot; alt=&quot;&quot; title=&quot;git logo&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Introduction&lt;/h2&gt;
&lt;p&gt;Recently I began to wonder if there was a way to have a collection of &lt;a href=&quot;https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks&quot;&gt;git hooks&lt;/a&gt; that could run on all of my git projects to save me the trouble of creating/editing hooks in each of my projects.  Yes, it is possible to do this for new projects, via the &lt;code&gt;git config --global init.templatedir&lt;/code&gt; command, but I have a lot of pre-existing git projects that I wanted to add a pre-push hook to, and I wanted to be able to make alterations to this hook after the fact that would affect all my projects.  Apparently, I&apos;m not the only person who needed this feature, because it was added in git release 2.9.&lt;/p&gt;
&lt;h2&gt;Details&lt;/h2&gt;
&lt;p&gt;Adding the global hooks was easy enough, thanks to this &lt;a href=&quot;https://stackoverflow.com/a/37293198&quot;&gt;stackoverflow&lt;/a&gt; answer, but I did run into a couple of caveats after I had the global hooks path set.&lt;/p&gt;
&lt;h3&gt;git config&lt;/h3&gt;
&lt;p&gt;To add the path to your global git configuration run the following command:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;git config --global core.hooksPath /path/to/my/centralized/hooks
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Hook file&lt;/h3&gt;
&lt;p&gt;The next step is to add your hook file and make it executable.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;touch /path/to/my/centralized/hooks/pre-push
chmod a+x /path/to/my/centralized/hooks/pre-push
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And then add what ever logic you&apos;d like the hook to execute.  I use &lt;a href=&quot;https://www.sonarqube.org/&quot;&gt;sonarqube&lt;/a&gt; to provide Continuos Inspection to my projects, so I wanted the &lt;code&gt;sonar-scanner&lt;/code&gt; to run on every push.  (I highly recommend &lt;a href=&quot;https://www.sonarqube.org/&quot;&gt;sonarqube&lt;/a&gt; for keeping bugs and code smells out, you should check it out if you&apos;re not familiar with it!).  I use the &lt;a href=&quot;https://fishshell.com/&quot;&gt;fish shell&lt;/a&gt;, so you might need a different shebang.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# /path/to/my/centralized/hooks/pre-push
#! /usr/bin/fish

command sonar-scanner
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So I created my hook and did a test push, to see that it worked as expected.  However, I do have some documentation only and small script projects that don&apos;t use the &lt;code&gt;sonar-scanner&lt;/code&gt;.  I was getting some ugly error messages when pushing these projects.  It didn&apos;t fail the push, because I wasn&apos;t checking the return code on &lt;code&gt;sonar-scanner&lt;/code&gt; command, but I still wanted to silence these messages, or not run &lt;code&gt;sonar-scanner&lt;/code&gt; at all on projects that didn&apos;t need it.  That was easy enough to do by checking for the presence of the &lt;code&gt;sonar-project.properties&lt;/code&gt; file before running the scanner.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# /path/to/my/centralized/hooks/pre-push
#! /usr/bin/fish
if test -e ./sonar-project.properties
    command sonar-scanner
end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Ok, so now that is running only when it should, but I bumped into another issue.  I had some projects that had project specific pre-push hooks that I expected to still be running before a push was executed.  I had assumed that adding these global hooks would be in addition to the project hooks, not overriding them.  However, that is not the behavior I was wanting; I still wanted any project specific hooks to be executed.  The fix for this was to check for the existence of a project level git hook and fire it if it exists.  I decided it would make more sense for my use case to fire it before the global hook logic was executed.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# /path/to/my/centralized/hooks/pre-push
#! /usr/bin/fish

if test -e ./.git/hooks/pre-push
    command sh ./.git/hooks/pre-push
end

if test -e ./sonar-project.properties
    command sonar-scanner
end
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;So there I had my global hook, that only ran the &lt;code&gt;sonar-scanner&lt;/code&gt; if it was necessary and made sure to also execute any local hooks. I&apos;m sure I&apos;ve only scratched the surface of the power of this, and I&apos;m looking forward to adding more functionality in the very near future.  I&apos;m going to investigate failing the push if the &lt;a href=&quot;https://www.sonarqube.org/&quot;&gt;sonarqube&lt;/a&gt; quality gate fails, next.  To improve my CI/CD work flow.  Have any suggestions or ideas for better hooks?  Please leave them in the comments below.&lt;/p&gt;
</description>
<pubDate>Sun, 17 Feb 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Version Bump for git using Fish Shell</title>
<link>https://eidson.info/post/git-version-bump</link>
<description>&lt;h1&gt;Version Bump for git using Fish Shell&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/fish-logo.png&quot; alt=&quot;&quot; title=&quot;Fish logo&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Intro&lt;/h2&gt;
&lt;p&gt;One feature that I really like from npm is the &lt;code&gt;version&lt;/code&gt; command which handles bumping either patch, minor, or major version number following the &lt;a href=&quot;https://semver.org/&quot;&gt;Semantic Versioning&lt;/a&gt; standards. This sets the version attribute in your &lt;code&gt;package.json&lt;/code&gt; file and creates a &lt;a href=&quot;https://git-scm.com/book/en/v2/Git-Basics-Tagging&quot;&gt;git tag&lt;/a&gt; using the new version number.&lt;/p&gt;
&lt;p&gt;For example you can run the &lt;code&gt;npm version minor&lt;/code&gt; command from the root of an npm project and it will change the version from &lt;code&gt;1.2.12&lt;/code&gt; to &lt;code&gt;1.3.0&lt;/code&gt; write this out to your &lt;code&gt;package.json&lt;/code&gt; file and create a git tag for the new version.&lt;/p&gt;
&lt;p&gt;Since the vast majority of my projects are php projects and not npm, I don&apos;t get a chance to use this feature nearly as much as I would like, so I found myself wishing there was a way to do this directly from git.&lt;/p&gt;
&lt;h2&gt;Details&lt;/h2&gt;
&lt;p&gt;I have been a big fan of the &lt;a href=&quot;https://fishshell.com/&quot;&gt;fish shell&lt;/a&gt; since first learning about it on &lt;a href=&quot;https://syntax.fm/show/013/the-command-line-for-web-developers&quot;&gt;syntax fm&lt;/a&gt;&apos;s &amp;quot;The Command Line for Web Developers&amp;quot; episode, mostly for the autosuggest and autocomplete features, but more recently I&apos;ve discovered the powerful scripting features. So I decided to see if I could implement this functionality through the command line via a &lt;code&gt;fish&lt;/code&gt; script.&lt;/p&gt;
&lt;p&gt;So basically what I wanted to do was to write a script that would read the current &lt;a href=&quot;https://git-scm.com/book/en/v2/Git-Basics-Tagging&quot;&gt;git tag&lt;/a&gt;, break it down into major, minor, and patch variables, increment the correct element, reassamble it into major.minor.patch format and create a new &lt;a href=&quot;https://git-scm.com/book/en/v2/Git-Basics-Tagging&quot;&gt;git tag&lt;/a&gt;. Once this was working I realized that if the major or minor version was incremented I needed to reset the following elements to zero. After that was worked out, I thought that I could save myself another step if it went ahead and pushed the new tag to my remote repo.&lt;/p&gt;
&lt;p&gt;At first I had it working with a custom function name, so from the root of my repo I could type &lt;code&gt;git_version minor&lt;/code&gt; and the new tag was calculated, created, and pushed. However, I don&apos;t personally like typing underscores, if I don&apos;t have to. So I wondered if I could &amp;quot;override&amp;quot; the git command and look for my custom command and then call git with the command line arguments, if it didn&apos;t see my custom &lt;code&gt;version&lt;/code&gt; command. That way it would feel like a more natural extension to git. That is when I came up with this solution:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# ~/.config/fish/functions/git.fish
function git

    if count $argv &amp;gt; /dev/null
        if [ $argv[1] = &apos;version&apos; ]
            git_version $argv
        else
            command git $argv
            return $status
        end
    else
        command git
        return $status
    end

end
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This worked beautifuly. If &lt;code&gt;git version minor&lt;/code&gt; is ran from the terminal, it calls my custom &lt;code&gt;git_version&lt;/code&gt; function and passes the arguments to it, if anything other than &lt;code&gt;version&lt;/code&gt; is passed as the first argument, it hands it off to git to handle. Of course, this can be altered to add many more custom commands to git, I&apos;m looking forward to adding more functionality in the future.&lt;/p&gt;
&lt;p&gt;And here is the custom function that is called if the &lt;code&gt;version&lt;/code&gt; argument is passed to &lt;code&gt;git&lt;/code&gt;. I&apos;m sure there is room for improvements, but the few dozen times I&apos;ve used it so far it behaved as expected. It expects an argument of either &apos;major&apos;, &apos;minor&apos;, or &apos;patch&apos; to determine which element to bump, with an optional &lt;code&gt;build&lt;/code&gt; argument of &lt;code&gt;alpha&lt;/code&gt; or &lt;code&gt;beta&lt;/code&gt; which will append a &lt;code&gt;-alpha&lt;/code&gt; or &lt;code&gt;-beta&lt;/code&gt; to the tag. There is also a &lt;code&gt;--force&lt;/code&gt; flag which will create and push the tag even if there are uncomitted changes on the branch. The other flag is a &lt;code&gt;--dry&lt;/code&gt; flag, if you just want to see the outcome of the command without creating a tag. Lastly, just running &lt;code&gt;git version&lt;/code&gt; will display the current version.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;# ~/.config/fish/functions/git_version.fish
function git_version
    set dry false
    set build &apos;&apos;
    set type &apos;&apos;
    set force false
    getopts $argv | while read -l key value
        switch $key
            case _
                switch $value
                    case major minor patch
                        set type $value
                    case alpha beta
                        set build $value
                end
            case d dry
                set dry true
            case f force
                set force true
            case v version
                _git_print_version
                return 0
            case \*
                # Handle unknown flags here
                echo unknown flag $key

        end
    end

    set v (git describe --abbrev=0 --tags 2&amp;gt;/dev/null)

    if [ $status != 0 ]
        set v &apos;0.0.0&apos;
    end

    # strip any thing from the hyphen after to remove -alpha or -beta
    set v (string split &amp;quot;-&amp;quot; -- $v)[1]
    set vmajor (string split &amp;quot;.&amp;quot; -- $v)[1]
    set vminor (string split &amp;quot;.&amp;quot; -- $v)[2]
    set vpatch (string split &amp;quot;.&amp;quot; -- $v)[3]

    if [ $type = &apos;patch&apos; ]
        set vpatch (math $vpatch + 1)
    else if [ $type = &apos;minor&apos; ]
        set vminor (math $vminor + 1)
        set vpatch 0
    else if [ $type = &apos;major&apos; ]
        set vmajor (math $vmajor + 1)
        set vpatch 0
        set vminor 0
    else
        echo $v

        return 0
    end

    if [ $build ]
        if [ $build = &apos;alpha&apos; ]
            set build alpha
        else if [ $build = &apos;beta&apos; ]
            set build beta
        else
            echo &amp;quot;The &apos;build&apos; can only be blank, alpha, or beta&amp;quot;
            return 1
        end
        set tag $vmajor.$vminor.$vpatch-$build
    else
        set tag $vmajor.$vminor.$vpatch
    end

    if $dry
        echo $tag
    else
        if git_is_dirty
            if $force
                echo &apos;Forcing new version&apos;
            else
                echo &apos;git is dirty - must use --force&apos;
                return 1
            end
        end
        git tag $tag
        git push origin master --tags
    end
end

function _git_print_version
    echo git verison bump 1.2.0
end

&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Granted, this only works for a specific work flow, and the keystrokes it saves are negligible, but it was a neat learning experience and now I am ready to tackle some more fish scripting to make my life easier.&lt;/p&gt;
&lt;p&gt;If you are interested in using this, it can be installed via &lt;a href=&quot;https://github.com/jorgebucaran/fisher&quot;&gt;fisher&lt;/a&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-fish&quot;&gt;fisher add eidsonator/fish-git-version
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The source code is available on github at &lt;a href=&quot;https://github.com/eidsonator/fish-git-version&quot;&gt;fish-git-version&lt;/a&gt; and pull requests are welcome, if you see any room for improvement.&lt;/p&gt;
&lt;p&gt;Please leave a comment if you can see any cons to me overriding git like this, or if you have any custom fish scripts you&apos;d like to share.&lt;/p&gt;
</description>
<pubDate>Sun, 10 Feb 2019 00:00:00 UTC</pubDate>
</item><item>
<title>Alphabetize your Way to More Readable Code</title>
<link>https://eidson.info/post/alphabetize-for-more-readable-code</link>
<description>&lt;h1&gt;Alphabetize your Way to More Readable Code&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/scrabble-tiles.jpeg&quot; alt=&quot;&quot; title=&quot;Scrabble pile&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Super short and simple post this time, because it&apos;s explaining a simple concept. The concept is so simple, that I&apos;m slightly embarrassed, almost shocked, that it took me almost 7 years of professional programming, and 3 and a half years of college to see and use this pattern.&lt;/p&gt;
&lt;p&gt;The tip? Any time you are writing code and the order of the lines is irrelevant, such as declaring class variables, creating a JSON object, populating an associative array, adding dependencies, configuring your configuration, ad infinitum, use alphabetical order.&lt;/p&gt;
&lt;p&gt;Instead of:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  name: &amp;quot;Marshall Mathers&amp;quot;,
  palms: &amp;quot;sweaty&amp;quot;,
  knees: &amp;quot;weak&amp;quot;,
  arms: &amp;quot;heavy&amp;quot;,
  nervous: true,
  sweater: &amp;quot;mom&apos;s spaghetti&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Use this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  arms: &amp;quot;heavy&amp;quot;,
  knees: &amp;quot;weak&amp;quot;,
  name: &amp;quot;Marshall Mathers&amp;quot;,
  nervous: true,
  palms: &amp;quot;sweaty&amp;quot;,
  sweater: &amp;quot;mom&apos;s spaghetti&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Sure, it does not rhyme as well, but if you need to change &lt;code&gt;nervous&lt;/code&gt; to false, it is much easier to find in the list. It does take a little extra brain power to add an item to the list, instead of just appending to the list, you may have to sing a phrase of the alphabet (unless you have a tool that sorts for you, see below). However, since code is read at an average of 10 times after it is written, you&apos;ll see the pay off when looking through a long JSON object or associative array to alter or fix something.&lt;/p&gt;
&lt;p&gt;I used to try and use some sort of hierarchical order with grouping in most places that I use this now, but there is no real hierarchy in most places that this can be implemented. Take for an example a &apos;person&apos; object or class. Sure, &apos;name&apos; is pretty important and would always go first (if not a uid), but how do you order the rest of the fields? Is a phone number more or less important than an address? As far as packages and dependencies go, one package might be used a lot more than another package, but I&apos;d argue that one is no more important than the other. If it wasn&apos;t important, it wouldn&apos;t be a dependency. In fact, it was when I started a new Symfony project a few months ago and noticed that they had added &lt;code&gt;&amp;quot;config&amp;quot;: {&amp;quot;sort-packages&amp;quot;: true}&lt;/code&gt; to composer.json and the profound effect that it had had on the readability of the &amp;quot;require&amp;quot; section as to what packages I was using in a project that I it had dawned on me that I should be using alphabetical order in as many places as I could to improve readability.&lt;/p&gt;
&lt;p&gt;It wouldn&apos;t really feel like one of my blog posts if I didn&apos;t somehow mention my favorite IDE, PhpStorm, so here it is: I&apos;ve recently discovered a plugin, called &lt;a href=&quot;https://plugins.jetbrains.com/plugin/5919-lines-sorter&quot;&gt;Lines Sorter&lt;/a&gt; by &lt;a href=&quot;https://github.com/syllant&quot;&gt;Sylvain Francois&lt;/a&gt;, that will do your sorting for you.  After you have the plugin installed, highlight the lines you wish to have sorted and then in the menu go to &lt;code&gt;Edit&amp;gt;Sort Lines&lt;/code&gt; or use the keyboard shortcut &lt;code&gt;alt + shift + L&lt;/code&gt; (I had to unmap this shortcut from the default &apos;Load Context&apos; option, first). This plugin will work in any of the JetBrains IDEs.&lt;/p&gt;
&lt;p&gt;Is this something you&apos;ve been doing for years?  Do you have any tips that are so simple you can&apos;t believe how long it took you to incorporate them? Do you know of a VS Code plugin to accomplish this?  Any arguments against using this tip? Please let me know in the comments.&lt;/p&gt;
</description>
<pubDate>Sun, 10 Dec 2017 00:00:00 UTC</pubDate>
</item><item>
<title>filter_var() is Your Friend</title>
<link>https://eidson.info/post/filter_var-is-your-friend</link>
<description>&lt;h1&gt;filter_var() is Your Friend&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/frustrated-mac-user.jpeg&quot; alt=&quot;&quot; title=&quot;Frustrated programmer&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;Intro&lt;/h2&gt;
&lt;p&gt;I was recently reading a blog post by Aaron Saray called
&lt;a href=&quot;https://aaronsaray.com/2017/in-php-false-is-sometimes-true&quot;&gt;In PHP, False is Sometimes True&lt;/a&gt;.
This is an issue that I&apos;ve encountered in the past and I&apos;d already considered
blogging about the solution, which is something Aaron left out of his blog post.&lt;/p&gt;
&lt;h2&gt;The Issue&lt;/h2&gt;
&lt;p&gt;I&apos;m sure that almost everyone that has dealt with handling html form data on the
backend from a &lt;code&gt;$_POST&lt;/code&gt; or a &lt;code&gt;$_GET&lt;/code&gt; variable via http or a JSON string has
encountered a situation in which trying to use a boolean value resulted in the
strange behavior of &amp;quot;false&amp;quot; equaling true. This happens because when casting a
string to a boolean, any non-empty string evaluates to true.&lt;/p&gt;
&lt;p&gt;Mr. Saray used the following code snippet to demonstrate this &amp;quot;phenomenon&amp;quot;.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$flag = &amp;quot;false&amp;quot;;
assert((bool) $flag === true);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Of course, the assetion here returns true, because &amp;quot;false&amp;quot; &lt;strong&gt;IS&lt;/strong&gt; true.&lt;/p&gt;
&lt;h2&gt;The Solution&lt;/h2&gt;
&lt;p&gt;In the past, before I learned about the filter_var function I would do something
like &lt;code&gt;assert($flag === &amp;quot;true&amp;quot;);&lt;/code&gt; This solution is perfectly valid, however, it
is also perfectly inflexible. If we want to support multiple frontends, some
which may actually send a boolean, or some that may use a 0 = false and 1 = true
schema, this will fail and leave us hunting bugs again.&lt;/p&gt;
&lt;p&gt;Introduced in php 5.2 and still valid in php 7+,
&lt;a href=&quot;http://php.net/manual/en/function.filter-var.php&quot;&gt;filter_var()&lt;/a&gt; is the best way
to tackle this problem. filter_var takes 3 arguments, the variable to filter,
the type of filter to use and optional filters, which are dependent on the type
of filter.&lt;/p&gt;
&lt;p&gt;Using a filter type of &lt;code&gt;FILTER_VALIDATE_BOOLEAN&lt;/code&gt; will return true for 1, &amp;quot;1&amp;quot;,
true, &amp;quot;true&amp;quot;, &amp;quot;on&amp;quot; and &amp;quot;yes&amp;quot;. Any other value will return false. So this solves
the inflexibility issue that arrises with my &apos;old&apos; solution.&lt;/p&gt;
&lt;p&gt;Solving the above bug with filter_var would look like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$flag = &amp;quot;false&amp;quot;;
$boolFlag = filter_var($flag, FILTER_VALIDATE_BOOLEAN);
assert($boolFlag === true);
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I&apos;ve demonstrated that using filter_var with the FILTER_VALIDATE_BOOLEAN filter
type is much more predictable than simply casting the variable, and much more
flexible than a hard coded solution. However, as implied by having a &apos;type&apos;
parameter in the filter_var function, you can do more than just safe boolean
casting with this function. Two of my other most used filter types are
FILTER_VALIDATE_EMAIL and FILTER_VALIDATE_IP which do pretty much as their names
imply. If the variable is a valid email or IP address, they will return the
variable, if not they return false. These are super useful in if statements, so
throw out those long confusing regular expressions that you googled that miss
edge cases anyway and start using filter_var. You can find a list of the other
&lt;a href=&quot;http://php.net/manual/en/filter.filters.validate.php&quot;&gt;Validate Filters here&lt;/a&gt;.
There are also
&lt;a href=&quot;http://php.net/manual/en/filter.filters.sanitize.php&quot;&gt;Sanatize filters&lt;/a&gt; that
will return an altered variable, so you can sanitize your inputs. Last but not
least, check out
&lt;a href=&quot;http://php.net/manual/en/function.filter-var-array.php&quot;&gt;filter_var_array()&lt;/a&gt; If
you have an array of flags, email or IP addresses that you need to validate in
one fell swoop.&lt;/p&gt;
</description>
<pubDate>Mon, 04 Dec 2017 00:00:00 UTC</pubDate>
</item><item>
<title>Create a File Watcher for php-cs-fixer in PhpStorm</title>
<link>https://eidson.info/post/phpstorm-file-watcher-php-cs-fixer</link>
<description>&lt;h1&gt;Create a File Watcher for php-cs-fixer in PhpStorm&lt;/h1&gt;
&lt;p&gt;
    &lt;img src=&quot;/img/phpstorm-2017_3-php-cs-fixer-linux.png&quot; alt=&quot;File Watcher Settings for Linux&quot; title=&quot;PhpStorm&quot; style=&quot;width: 100%&quot;&gt;
&lt;/p&gt;
&lt;h2&gt;Intro&lt;/h2&gt;
&lt;p&gt;This is a quick an easy guide to setting up a file watcher on &lt;a href=&quot;&quot;&gt;PhpStorm&lt;/a&gt; so that every time a php file is saved,
&lt;a href=&quot;https://github.com/FriendsOfPHP/PHP-CS-Fixer&quot;&gt;php-cs-fixer&lt;/a&gt; is ran on the file.  More than just a linter, php-cs-fixer will update your code to match coding standards
such as the official PSR-1 and PSR-2, as well as community standards such as the &lt;a href=&quot;&quot;&gt;Symfony&lt;/a&gt; one.  It will also do some
modernization and micro-optimizations.&lt;/p&gt;
&lt;h2&gt;Steps&lt;/h2&gt;
&lt;h3&gt;Install php-cs-fixer&lt;/h3&gt;
&lt;p&gt;There are a few different installation options, but the &lt;a href=&quot;&quot;&gt;Composer&lt;/a&gt; install seemed like the easiest (like it always does).
If you don&apos;t have composer installed you can follow the link above to install it.  After Composer is installed, from the
terminal run:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;$ composer global require friendsofphp/php-cs-fixer
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;After it installs you can try and run it from the terminal.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;$ php-cs-fixer --help
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;If it doesn&apos;t run, it&apos;ll need added to the path.  Here is a linux command, my Windows box worked out of the box.  I&apos;m
assuming the Composer Windows installer handled this for me.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-bash&quot;&gt;$ export PATH=&amp;quot;$PATH:$HOME/.composer/vendor/bin&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Create the PhpStorm File Watcher&lt;/h3&gt;
&lt;p&gt;From inside of a project in PhpStorm, open up the settings page.  From the menu go to &lt;code&gt;File &amp;gt; Settings&lt;/code&gt; or use the keyboard
shortcut &lt;code&gt;ctrl+alt+s&lt;/code&gt; (in Windows or linux).&lt;/p&gt;
&lt;p&gt;From there you can start typing &apos;file watcher&apos; to narrow down the options and then select &lt;code&gt;File Watchers&lt;/code&gt; from under the
&lt;code&gt;Tools&lt;/code&gt; tab.&lt;/p&gt;
&lt;p&gt;Next either press &lt;code&gt;alt + insert&lt;/code&gt; or press the green plus sign icon in the upper right-hand corner to create a new file watcher.&lt;/p&gt;
&lt;p&gt;Choose the &lt;code&gt;Custom Template&lt;/code&gt; option.&lt;/p&gt;
&lt;p&gt;In the dialog box that opens, give your watcher a name, I chose &amp;quot;php-cs-fixer&amp;quot;, for the sake of simplicity.&lt;/p&gt;
&lt;p&gt;Set the File type to &amp;quot;PHP&amp;quot; and Scope to &amp;quot;Current File&amp;quot;.&lt;/p&gt;
&lt;p&gt;Set the Program to &amp;quot;php-cs-fixer&amp;quot;.  In my Windows environment, I had to add the &apos;.bat&apos; file extension (example below).
In my linux environment I had to use the full path to my &lt;code&gt;~/composer/vendor/bin/php-cs-fixer&lt;/code&gt; (example above).  Run
&lt;code&gt;which php-cs-fixer&lt;/code&gt; from the terminal to get the full path.  This command works on Windows 10, too.&lt;/p&gt;
&lt;p&gt;The Arguments is where all the work is done.  First type &lt;code&gt;fix&lt;/code&gt; which is the command for php-cs-fixer to actually do something.
Next add any flags you want to pass in for the rules.  Finally add &lt;code&gt;$FilePath$&lt;/code&gt; which is a PhpStorm variable for the full
path to current file, up to and including the name and extension.&lt;/p&gt;
&lt;p&gt;Set the &amp;quot;Output paths to refresh&amp;quot; to &lt;code&gt;$FilePath$&lt;/code&gt; so the editor reload the current file as soon as the changes are saved.&lt;/p&gt;
&lt;p&gt;The final step and a very important one is to uncheck the &amp;quot;Auto-save edited files to trigger the watcher&amp;quot;  checkbox
under &amp;quot;Advanced Options.&amp;quot;  If this is checked,
the watcher will run with each keystroke in the file editor and PhpStorm will become confused if the memory (editor) changes
or the disk(php-cs-fixer) changes are the ones to use.  If you are still on PhpStorm 2017.2 this option is labeled &amp;quot;Immediate file synchronization&amp;quot;.&lt;/p&gt;
&lt;p&gt;Click &amp;quot;OK&amp;quot; to save your file watcher, and then close the settings dialog.&lt;/p&gt;
&lt;p&gt;
    &lt;img src=&quot;/img/file-watcher-php-cs-fixer-windows.png&quot; alt=&quot;File Watcher Settings for Windows&quot; title=&quot;PhpStorm&quot; style=&quot;width: 100%&quot;&gt;
&lt;/p&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;Setting up this file watcher in PhpStorm is super easy and crazy useful.&lt;/p&gt;
&lt;p&gt;Another option would have been to use the external tools option of PhpStorm, which is the original
way I was going to do this, inspired by a &lt;a href=&quot;https://laracasts.com/series/how-to-be-awesome-in-phpstorm/episodes/26&quot;&gt;Laracasts tutorial&lt;/a&gt;.
The only downfall to using php-cs-fixer as an external tool, is that you have to manually trigger
it.  I wanted php-cs-fixer to be a fully automated step in my work flow.&lt;/p&gt;
&lt;p&gt;One more, fully automated, way to integrate php-cs-fixer would be to use a  git pre-commit hook.
I still like the file watcher option better, because it allows me to see in the editor if there
are still warnings from other linters and sniffers if there are things that could still be
improved even after php-cs-fixer is ran.&lt;/p&gt;
</description>
<pubDate>Thu, 30 Nov 2017 00:00:00 UTC</pubDate>
</item><item>
<title>php 7.3 - Flexible heredoc &amp; nowdoc Syntax</title>
<link>https://eidson.info/post/php-flexible-heredoc-nowdoc-syntax</link>
<description>&lt;h1&gt;php 7.3 - Flexible heredoc &amp;amp; nowdoc Syntax&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/php.png&quot; alt=&quot;php logo&quot; title=&quot;php logo&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Although we&apos;ve still got a while to go before we see php 7.3, since we&apos;re still 4 days away from the release of php 7.2,
I&apos;ve already seen one new feature that looks like it will make its way into 7.3 that I am excited about.  This feature
is more flexible syntax for heredoc and nowdoc statements.  Here is the official &lt;a href=&quot;https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes&quot;&gt;rfc&lt;/a&gt;
if you&apos;d like to read it.&lt;/p&gt;
&lt;h2&gt;What are heredocs and nowdocs?&lt;/h2&gt;
&lt;p&gt;Heredocs and nowdocs are the easiest and cleanest ways in php to use and format multiline strings.&lt;/p&gt;
&lt;p&gt;Instead of:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$html = &apos;&amp;lt;ul&amp;gt;&apos;;
$html .= &apos;&amp;lt;li&amp;gt;item 1&amp;lt;/li&amp;gt;&apos;;
$html .= &apos;&amp;lt;li&amp;gt;item 2&amp;lt;/li&amp;gt;&apos;;
$html .= &apos;&amp;lt;li&amp;gt;item 3&amp;lt;/li&amp;gt;&apos;;
$html = &apos;&amp;lt;/ul&amp;gt;&apos;;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;We can use:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$html = &amp;lt;&amp;lt;&amp;lt;html
&amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;item 1&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item 2&amp;lt;/li&amp;gt;
    &amp;lt;li&amp;gt;item 3&amp;lt;/li&amp;gt;
&amp;lt;/ul&amp;gt;
html
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The only difference between a heredoc and a nowdoc is that a heredoc performs string interpolation, turning your variables
into the string they represent, while a nowdoc does not.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;//heredoc example
$name = &apos;Todd Eidson&apos;;
$text = &amp;lt;&amp;lt;&amp;lt;txt
My name is $name
txt

echo $text;
// outputs &apos;My name is Todd Eidson&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;//nowdoc example
$name = &apos;Todd Eidson&apos;;
// notice the single quotes around the marker 
$text = &amp;lt;&amp;lt;&amp;lt;&apos;txt&apos;
My name is $name
txt

echo $text;
// outputs &apos;My name is $name&apos;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;One great thing about using a heredoc/nowdoc within a good IDE (like my favorite,
&lt;a href=&quot;https://www.jetbrains.com/phpstorm/&quot;&gt;PhpStorm&lt;/a&gt;) is that php allows you to pick your own heredoc marker, and PhpStorm
is smart enough to give you syntax highlighting inside the heredoc based on the marker
used.  For example if you use &lt;code&gt;sql&lt;/code&gt; or &lt;code&gt;HTML&lt;/code&gt; for your marker name, your heredoc
string will use the code highlighting of the marker, making mistakes easy to spot.&lt;/p&gt;
&lt;h2&gt;Caveat&lt;/h2&gt;
&lt;p&gt;The only caveat (for now) when using a heredoc/nowdoc is that the end of statment marker must be the first and only thing
on the line.  This leads to left aligned text in the middle of a function or method that can be quite jarring when quickly
scanning code, much like coming to a stop sign in the middle of an interstate, your brain has to slow down for a second to
figure out why your indentation is not being properly followed.&lt;/p&gt;
&lt;p&gt;Like so:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;class MyClass
{
    public function MyFunction($variable)
    {
        if ($variable) {
            $html = &amp;lt;&amp;lt;&amp;lt;html
Why is this code against the left margin?
It would be really nice if it was
properly indented.             
html
        }
        return $html;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;The Changes&lt;/h2&gt;
&lt;p&gt;In php 7.3 we will be able to indent the end of heredoc marker to improve readability.
Any whitespace before ending marker will also be stripped off the front of the each
line in the multiline string.  Any line that is not indented to at least the level
of the ending marker will throw an error.&lt;/p&gt;
&lt;p&gt;An example:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;class MyClass
{
    public function MyFunction($variable)
    {
        if ($variable) {
            $html = &amp;lt;&amp;lt;&amp;lt;html
                Isn&apos;t this so much easier to read?
                It is really nice that it is
                properly indented.
                And so much easier to read!             
                html
        }
        return $html;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;The other chage is that the ending marker does not have to be followed by a new line.
I can&apos;t remember a time at which I wished for this ability, so I&apos;m not nearly as
excited about this as I am the ability to indent the ending marker, but I&apos;m sure
some people will get some use out of it.  I guess it could be useful if using multiple
heredocs in a function call or an array.&lt;/p&gt;
&lt;p&gt;Like this:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;// The old way:
myFunction(&amp;lt;&amp;lt;&amp;lt;txt
This is
the first parameter
txt
, &amp;lt;&amp;lt;&amp;lt;txt
This is
the second parameter
txt
);


// The new way
myFunction(&amp;lt;&amp;lt;&amp;lt;txt
This is
the first parameter
txt, &amp;lt;&amp;lt;&amp;lt;txt
This is
the second parameter
txt
);
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;Conclusion&lt;/h2&gt;
&lt;p&gt;I&apos;m really looking forward to when I can get switched over to 7.3 (or 8, whichever comes
first) so I can take advantage of this new feature and clean up all my heredocs. I do
recommend reading the &lt;a href=&quot;https://wiki.php.net/rfc/flexible_heredoc_nowdoc_syntaxes&quot;&gt;rfc&lt;/a&gt; as
there are some nuances concerning marker names and a raised backwards incompatability issue
that I don&apos;t go over in this post.&lt;/p&gt;
&lt;p&gt;What are your thoughts on this change? Yay, nay, or meh?&lt;/p&gt;
</description>
<pubDate>Sun, 26 Nov 2017 00:00:00 UTC</pubDate>
</item><item>
<title>The Joy of Rotating Logs in Symfony</title>
<link>https://eidson.info/post/rotating-logs-symfony</link>
<description>&lt;h1&gt;The Joy of Rotating Logs in Symfony&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/logs.jpg&quot; alt=&quot;logs&quot; title=&quot;Logs&quot; /&gt;&lt;/p&gt;
&lt;p&gt;Switching from my hand-made, hodgepodge, cobbled together collection of libraries that
was trying to act more and more like a &amp;quot;framework&amp;quot; every day to a full-blown real, properly
developed, properly tested framework like Symfony continues to be the best decision I&apos;ve made
in my programming career thus far.  I&apos;ve learned so much about clean code, design patterns,
SOLID principles and many other programming best practices from working within Symfony&apos;s
MVC (Model View Controller) pattern and reading its documentation and code when I need to
extend it to bow to my every whim.&lt;/p&gt;
&lt;p&gt;One great feature of Symfony is the highly configurable logging, implemented via monolog.&lt;br /&gt;
Way back in my pre-Symfony days, when I encountered an exception in development, my first step was
firing up xdebug and stepping through the code line by line to inspect variables and watch where
the logic was taking me to try and find the root cause of the bug.  Now my first step is to head
to the log file and see what was happening at the time of the exception (for JSON calls, anyway.
The log is spit out on the screen if the result of the call was to render a page).&lt;/p&gt;
&lt;p&gt;I prefer text logging verses logging to a database, for the simplicity of writing and reading.&lt;br /&gt;
One problem with text logging is that the files can grow too big, too fast.  Most text editors
will choke on a log file that is too big.  Or, the worst case scenario may be encountered, which
is the log file becomes so large that it eats up all available disk space on the server, bringing
the server to its knees. Thankfully I&apos;ve only encountered this once, due to leaving a debug flag on
in production.  Which brings up another great thing about using Symfony, thanks to the app_dev.php file,
no more debug flags.&lt;/p&gt;
&lt;p&gt;To combat the issue of log files growing too large, one of the first things I do in any new Symfony
project is to set the log type to &lt;code&gt;rotating_file&lt;/code&gt; which is a standard feature in monolog, but beautifully
exposed via the Symfony configuration file.&lt;/p&gt;
&lt;p&gt;This can be set in both your prod and dev config files, to give the desired behavior for each environment.&lt;/p&gt;
&lt;h3&gt;Development&lt;/h3&gt;
&lt;p&gt;In the &lt;code&gt;config_dev.yml&lt;/code&gt; simply change the &lt;code&gt;main&lt;/code&gt; handler type from &lt;code&gt;stream&lt;/code&gt; to &lt;code&gt;rotating_file&lt;/code&gt; and just
below that add the &lt;code&gt;max_files&lt;/code&gt; to keep.  I set mine to &lt;code&gt;1&lt;/code&gt; in dev, since I don&apos;t believe that a development
log file needs to persist past a single day. Voilà, a fresh clean log file every morning when I access my log
in the development environment.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yml&quot;&gt;# app/config/config_dev.yml
monolog:
    handlers:
        main:
            # change this line
            type: rotating_file
            # add this line
            max_files: 1
            path: &apos;%kernel.logs_dir%/%kernel.environment%.log&apos;
            level: debug           
            channels: [&apos;!event&apos;]
        console:
            type: console
            process_psr_3_messages: false
            channels: [&apos;!event&apos;, &apos;!doctrine&apos;, &apos;!console&apos;]
        # To follow logs in real time, execute the following command:
        # `bin/console server:log -vv`
        server_log:
            type: server_log
            process_psr_3_messages: false
            host: 127.0.0.1:9911
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Production&lt;/h3&gt;
&lt;p&gt;In your project&apos;s production environment configuration file - &lt;code&gt;config_prod.yml&lt;/code&gt;, we&apos;ll make the same changes,
but under the &lt;code&gt;nested&lt;/code&gt; handler.  The nested handler is another great aspect of logging with monolog from inside
of a Symfony project.  If the &lt;code&gt;main&lt;/code&gt; handler is set to a &lt;code&gt;fingers_crossed&lt;/code&gt; type, it caches the log for every
request.  The only time that it logs anything, is if the &lt;code&gt;action_level&lt;/code&gt; threshold is passed.  In the example below,
if a log level of error or higher is caught, it passes the cached log to the handler set in the &lt;code&gt;handler&lt;/code&gt; parameter.
This allows logging of the full request stack, but only in the event that an error occurs.  This way only
meaningful logs are stored, but we get the entire log for that request.  This is another feature that keeps are
logs from growing too large.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-yml&quot;&gt;# app/config/config_prod.yml
monolog:
    handlers:
        main:
            type: fingers_crossed
            action_level: error
            handler: nested
        nested:
            # change this line
            type:  rotating_file
            # add this line
            max_files: 7
            path:  &amp;quot;%kernel.logs_dir%/%kernel.environment%.log&amp;quot;
            level: debug           
        console:
            type: console
            process_psr_3_messages: false
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Log files location&lt;/h3&gt;
&lt;p&gt;Another thing I like to do with the logging, is change the location of where my log files are stored.  By default,
the log files are stored in &lt;code&gt;project_root/var/logs&lt;/code&gt;.  My deployment process creates each new release in a &lt;code&gt;releases&lt;/code&gt;
directory in my production environment, and my webroot is nothing more than a symlink that that points to the
most recent releases directory. If I keep the default log file location, each release uses its own directory
to store log files.  By moving the logs directory up one level, each release uses a shared log location so
my log files persist across new releases of my project.  Another benefit to this is not having to worry about
setting write permissions for the www-data user that Apache uses for the log directory in each new release.
It is easy to alter the &lt;code&gt;getLogDir()&lt;/code&gt; method in your &lt;code&gt;AppKernel&lt;/code&gt; class to use one level up, or any other custom
location in which you wish to store your log files.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;    // project_root/app/AppKernel.php
    public function getLogDir()
    {
        // I&apos;ve inserted the &apos;../&apos; to move the logs up one directory from the project root
        return dirname(__DIR__).&apos;/../var/logs&apos;;
    }
&lt;/code&gt;&lt;/pre&gt;
&lt;h3&gt;Easy log file viewing&lt;/h3&gt;
&lt;p&gt;As easy as it is to view log files in development, to logs in your production environment, you have to log
in to your production server, navigate to the log directory and then open them with the log viewer/text editor
of your choice.  It was those couple extra steps that inspired me, after not finding any existing solutions
that I liked, to write a Symfony bundle that allows you to view your logs  from your web browser.&lt;br /&gt;
My WebLogViewerBundle includes color-coded, collapsable log levels, and formatted JSON and SQL.
It can be included via Composer (&lt;a href=&quot;https://packagist.org/packages/greenskies/web-log-viewer-bundle&quot;&gt;packagist&lt;/a&gt;)
and the source can be found on &lt;a href=&quot;https://github.com/greenskies/WebLogViewerBundle&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Hopefully, you can see the benefits and ease of using rotating log files in your Symfony projects.  How do you
configure your logging in Symfony?&lt;/p&gt;
</description>
<pubDate>Fri, 24 Nov 2017 00:00:00 UTC</pubDate>
</item><item>
<title>Editing Shared Libraries in PhpStorm with Composer and git</title>
<link>https://eidson.info/post/editing-shared-libraries-in-phpstorm-with-composer-and-git</link>
<description>&lt;h1&gt;Editing Shared Libraries in PhpStorm with Composer and git&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/logo-composer-transparent4.png&quot; alt=&quot;Composer logo&quot; title=&quot;Composer Logo&quot; /&gt;&lt;/p&gt;
&lt;h2&gt;The &amp;quot;Old&amp;quot; Workflow&lt;/h2&gt;
&lt;p&gt;When I started my current position way back in the winter of 2013 as the sole Application Developer in a
corporate/enterprise environment, I was tasked with maintaining existing web applications, porting Visual Basic
apps into a web environment, as well as creating new applications.  Each of the php applications that I had inherited
had several shared dependencies that were maintained independently in their separate project directories.
Any bug that was found and fixed in one of these &apos;libraries&apos; had to be copied manually to the other projects
that were using this library.  Seeing this as a clear violation of the DRY (don&apos;t repeat yourself) principle,
I decided to move the libraries into a central location that could be shared among the different projects via the
php include path.  This approach worked fine, until I wanted to start introducing changes that broke backwards
compatibility for the benefit of one project.  It would break the other projects until they had been updated to
use the newer version of the library.  (I was still using manual deployment, no unit testing, no frameworks, it was a
dark and dreary time.)&lt;/p&gt;
&lt;h2&gt;Take Two&lt;/h2&gt;
&lt;p&gt;It was about this time that I realized that it would indeed be best to keep individual copies of the libraries
with each project, to prevent the aforementioned problems with backwards compatibility breaking changes, but these
libraries needed to be managed from a central location.  I had recently convinced my manager that we should switch
from svn to git, and I thought that maybe using &lt;a href=&quot;https://git-scm.com/docs/git-submodule&quot;&gt;git-submodule&lt;/a&gt; would be
the answer to the question of how to manage these dependencies.  It wasn&apos;t.  It was messy.  It was broken.  It was
the worst idea I had had in a long series of bad ideas in trying to tackle this problem.  It was also about this
time that I had realized that what I was trying to do was write my own framework.  I had a database connection library,
a library that auto-wired my templating engine, an ldap connection library... I needed to stop trying to reinvent the
wheel and just learn and use a real framework.&lt;/p&gt;
&lt;h2&gt;Composer to the Rescue&lt;/h2&gt;
&lt;p&gt;I decided to learn and implement the &lt;a href=&quot;https://symfony.com/&quot;&gt;Symfony Framework&lt;/a&gt;.  Learning Symfony included learning
about &lt;a href=&quot;https://getcomposer.org/&quot;&gt;Composer&lt;/a&gt; which I was vaguely familiar with, but totally unaware of how powerful it is.
In hindsight I should have realized that a &amp;quot;Dependency Manager&amp;quot; was exactly what I needed to manage my dependencies.
I soon learned that I could include my own repositories in my projects via the Composer configuration.  Using this I
could make changes to my library inside of my project, copy these changes to my library repository, upload the changes
to my central repository and then get the changes in my other projects by using &lt;code&gt;composer update&lt;/code&gt;.  This was a couple
extra steps than I wanted to take, but it was the workflow I had been looking for all along.&lt;/p&gt;
&lt;h2&gt;Composer, git, and PhpStorm&lt;/h2&gt;
&lt;p&gt;I soon realized that when one includes a repository with a type of &apos;vcs&apos; through composer, you not only get a copy
of the files in that project, you get a copy of the entire repo, up to and including the &lt;code&gt;.git&lt;/code&gt; directory.  So basically
I could make changes to my repo from inside of my &lt;code&gt;vendor&lt;/code&gt; directory and commit and push to my central repository
straight from there.  When I learned that I could inform my favorite IDE &lt;a href=&quot;https://www.jetbrains.com/phpstorm/&quot;&gt;PhpStorm&lt;/a&gt;
about these &apos;sub&apos; repositories and commit and push directly from the user interface my current workflow was concreted
and perfected (for now).&lt;/p&gt;
&lt;h2&gt;Steps to implement this process&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;In the project&apos;s &lt;code&gt;composer.json&lt;/code&gt; file add a &lt;code&gt;repositories&lt;/code&gt; section pointing to your shared library.&lt;/li&gt;
&lt;li&gt;Add your repository as a dependency in the &lt;code&gt;require&lt;/code&gt; section
&lt;ul&gt;
&lt;li&gt;This will also work if use &lt;a href=&quot;https://github.com/composer/satis&quot;&gt;satis&lt;/a&gt; to require your repositories&lt;/li&gt;
&lt;/ul&gt;
&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
    &amp;quot;repositories&amp;quot;: [
        {
            &amp;quot;type&amp;quot;: &amp;quot;vcs&amp;quot;,
            &amp;quot;url&amp;quot;: &amp;quot;git@github.com:greenskies/WebLogViewerBundle.git&amp;quot;
        }
    ],
    &amp;quot;require&amp;quot;: {
        // other dependencies
        &amp;quot;greenskies/web-log-viewer-bundle&amp;quot;: &amp;quot;dev-master&amp;quot;
    }
}
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Open up the settings in PhpStorm via File &amp;gt; Settings or &lt;code&gt;ctrl + alt + s&lt;/code&gt; (in Windows or Linux)&lt;/li&gt;
&lt;li&gt;Click on the &lt;code&gt;Version Control&lt;/code&gt; tab&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
    &lt;img src=&quot;/img/Settings.png&quot; alt=&quot;PhpStorm Settings&quot; title=&quot;PhpStorm&quot; style=&quot;width: 100%&quot;&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Click on the green &lt;code&gt;+&lt;/code&gt; (plus sign) in the upper right hand corner of the dialog to add another vcs path&lt;/li&gt;
&lt;li&gt;Add the path to your library inside of your vendor folder - PhpStorm should select the &lt;code&gt;git&lt;/code&gt; vcs type for you&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;
    &lt;img src=&quot;/img/Add_VCS_Directory_Mapping.png&quot; alt=&quot;Add VCS Directory Mapping&quot; title=&quot;Add VCS Directory Mapping&quot; style=&quot;width: 100%&quot;&gt;
&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;Now, anytime you make any change to your shared library, you can select &amp;quot;git &amp;gt; Commit file&amp;quot; or &amp;quot;Commit Directory&amp;quot; to
commit and push your changes!  (You can also use git from the command line/terminal from inside of shared library to commit &amp;amp; push)&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Do you have any tips and tricks to integrate git, Composer, and PhpStorm into your worklow? If so, please share
them in the comments.&lt;/p&gt;
</description>
<pubDate>Sun, 19 Nov 2017 00:00:00 UTC</pubDate>
</item><item>
<title>PHP_EOL is Broken (Sometimes)</title>
<link>https://eidson.info/post/php_eol_is_broken</link>
<description>&lt;h1&gt;PHP_EOL is Broken (Sometimes)&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/php.png&quot; alt=&quot;php logo&quot; title=&quot;php logo&quot; /&gt;&lt;/p&gt;
&lt;h3&gt;What is PHP_EOL?&lt;/h3&gt;
&lt;p&gt;Introduced in version 5.0.2 of php, &lt;code&gt;PHP_EOL&lt;/code&gt; is a string constant that represents the correct end of line symbol for
the platform that you are running php on.
So on Windows this should be set to &lt;code&gt;&amp;quot;\r\n&amp;quot;&lt;/code&gt; (carriage return and line feed) and on a *nix system it should be set to
&lt;code&gt;&amp;quot;\n&amp;quot;&lt;/code&gt; (only line feed).&lt;/p&gt;
&lt;h3&gt;Where is it Used?&lt;/h3&gt;
&lt;p&gt;You &lt;strong&gt;SHOULD&lt;/strong&gt; use it when programmatically creating a text file via php.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$text = &apos;Line one&apos; . PHP_EOL;
$text .= &apos;Line two&apos; . PHP_EOL;
 
$file = fopen(&apos;file.txt&apos;, &apos;w&apos;);
fputs($file, $text);
fclose($file);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;This will create a platform correct end of line separator, and ensure portability in a project.&lt;/p&gt;
&lt;h3&gt;Okay, So How is it Broken?&lt;/h3&gt;
&lt;p&gt;Usually when one is working with strings that contain multiple lines and they want to create an array that consists of
each individual line they will use:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$array = explode(PHP_EOL, $string);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;However,&lt;/em&gt; in the last couple of weeks I&apos;ve been bitten by two different bugs caused by the very simple line of code above.&lt;/p&gt;
&lt;h5&gt;Bug #1&lt;/h5&gt;
&lt;p&gt;The first was when I was working on my &lt;a href=&quot;https://github.com/eidsonator/WebLogViewerBundle&quot;&gt;Web Log Viewer Bundle&lt;/a&gt; project
which is a &lt;a href=&quot;https://symfony.com/&quot;&gt;Symfony&lt;/a&gt; bundle for viewing log files created by a Symfony project online, so logging
in to the server to view them in not necessary.  This project parses log files, formats the lines, and displays them
in an HTML table.  I was using &lt;code&gt;$array = explode(PHP_EOL, $string);&lt;/code&gt;, but when running this on a Windows box, my string
was not exploding correctly and I was getting &lt;code&gt;$array = [$string]&lt;/code&gt; instead of &lt;code&gt;$array = [line1, line2, line3, ...]&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;Symfony uses &lt;a href=&quot;https://github.com/Seldaek/monolog&quot;&gt;monolog&lt;/a&gt;, and I didn&apos;t investigate how monolog writes its end of line
symbols in an attempt to determine the root cause of this bug, but I did need to find a fix.
&lt;em&gt;Help me stackoverflow, you&apos;re my only hope.&lt;/em&gt;&lt;/p&gt;
&lt;h5&gt;Bug #2&lt;/h5&gt;
&lt;p&gt;I&apos;ve recently started using &lt;a href=&quot;http://www.magephp.com/&quot;&gt;Magallanes&lt;/a&gt; to deploy my projects, instead of my old hacky way of
using a git post commit hook to push my changes to a git repo on the production server and then logging in to the production
server and manually performing 5 or 6 steps to update dependencies, build assets, and clear caches. I did have to make
a handful of really small changes to make it work in a Windows environment, but oh, man, was it worth it. Lots more on
how I improved my deployment process with Magallanes in later posts.&lt;/p&gt;
&lt;p&gt;I mentioned that I had to make some changes to make Magallanes work in a Windows environment, and I thought that I had
everything worked out until I noticed this next bug.  I use the &amp;quot;releases&amp;quot; option of Magallanes that uploads the current
release to a timestamp-based-name directory inside of the &lt;code&gt;releases&lt;/code&gt; directory and then creates a symlink named &lt;code&gt;current&lt;/code&gt;
that points to the newest directory in the &lt;code&gt;releases&lt;/code&gt; folder.  In the Magallanes config file, there is a parameter named
&lt;code&gt;releases&lt;/code&gt; that indicates the number of previous releases that should be kept on the server, in case there is a need to
rollback to an earlier release.  I noticed that in one of my &lt;code&gt;releases&lt;/code&gt; directory, there were about 10 previous releases,
when I had this configuration parameter set to 5.  Something was broken.&lt;/p&gt;
&lt;p&gt;I went looking through the &lt;a href=&quot;https://github.com/andres-montanez/Magallanes/blob/master/src/Task/BuiltIn/Deploy/Release/CleanupTask.php&quot;&gt;cleanup task code&lt;/a&gt;
and discovered that it was using &lt;code&gt;ls -1&lt;/code&gt; via ssh to get a string of all the directories inside of the &lt;code&gt;releases&lt;/code&gt; directory
and then using my recent archnemesis &lt;code&gt;$releases = explode(PHP_EOL, trim($releases));&lt;/code&gt; to turn that string into an array
and doing all the work on the array.  I was pretty confident that the bug was in the explode statment, due to my recent
experience with Bug #1.  After stepping through the code using xdebug, my hunch was confirmed, and I knew just where to
find the fix.&lt;/p&gt;
&lt;h3&gt;The Fix&lt;/h3&gt;
&lt;blockquote&gt;
&lt;p&gt;Some people, when confronted with a problem, think &amp;quot;I know, I&apos;ll use regular expressions.&amp;quot;
Now they have two problems. -  Jamie Zawinski&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;After discovering Bug #1, I fired up my trusty google machine and went in search to a solution for this problem.
Sure enough, the first search result was a &lt;a href=&quot;https://stackoverflow.com/a/5053394&quot;&gt;stackoverflow answer&lt;/a&gt; that fixed the bug.
It was the following simple, one-line, cross-platform fix:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;Replace:&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$lines = explode(PHP_EOL, $str);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;em&gt;With:&lt;/em&gt;&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-php&quot;&gt;$lines = preg_split(&apos;/\n|\r\n?/&apos;, $str);
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;So, of course, I knew the perfect fix when I came across Bug #2, just a few short weeks later.&lt;/p&gt;
&lt;h3&gt;Conclusion&lt;/h3&gt;
&lt;p&gt;Although I was more concerned with fixing the bugs than I was with finding the root cause of the bugs, which would have
required I solve the riddle &amp;quot;when is the end of line not the end of the line?&amp;quot;, I was able to implement a nice and easy
cross-platform solution and come to the conclusion that PHP_EOL is Broken (Sometimes).&lt;/p&gt;
</description>
<pubDate>Sun, 12 Nov 2017 00:00:00 UTC</pubDate>
</item><item>
<title>Code Highlighting in HTML</title>
<link>https://eidson.info/post/2017-10-22_code_highlighting</link>
<description>&lt;h1&gt;Code Highlighting in HTML&lt;/h1&gt;
&lt;p&gt;&lt;img src=&quot;/img/computer_code.png&quot; alt=&quot;alt text&quot; title=&quot;Highlighted Code&quot; /&gt;&lt;/p&gt;
&lt;p&gt;I&apos;ve been wanting to start blogging for quite some time now, and I figured there is no time like the present.
I am familiar with both &lt;a href=&quot;https://wordpress.com&quot;&gt;WordPress&lt;/a&gt; and &lt;a href=&quot;https://www.drupal.org/&quot;&gt;Drupal&lt;/a&gt;, but I wanted to &amp;quot;roll my own&amp;quot; both for flexibility and as a learning experience.
Since this blog is  going to be code heavy, one thing that was really important to me was code highlighting in the display.
I really like the code highlighting on the &lt;a href=&quot;http://symfony.com/doc/current/setup.html&quot;&gt;Symfony documentation pages&lt;/a&gt;, and I&apos;ve used that in some of my own documentation pages,
however, that is using &lt;a href=&quot;http://www.sphinx-doc.org/en/stable/&quot;&gt;Sphinx&lt;/a&gt; and &lt;code&gt;.rst&lt;/code&gt; files, which requires a compilation step. I was looking for a way to have markdown files parsed by a real-time HTML converter to give me syntax highlighted code in HTML.
That&apos;s how I discovered &lt;a href=&quot;https://highlightjs.org/&quot;&gt;highlightjs&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;&lt;em&gt;highlightjs&lt;/em&gt; will take any code that inside of an element that has a class of &lt;code&gt;{language-name}&lt;/code&gt;, &lt;code&gt;lang-{language-name}&lt;/code&gt;, or &lt;code&gt;language-{language-name}&lt;/code&gt;
and wrap keywords, built-ins, and strings/numbers in spans that have highlighting classes assigned to them.
There is a cdn version available that has support for 23 of the most popular languages that can be added to your project in
3 easy steps.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;First add the stylesheet to the &lt;code&gt;head&lt;/code&gt; section of the HTML page.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;link rel=&amp;quot;stylesheet&amp;quot; href=&amp;quot;//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/default.min.css&amp;quot;&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Next add the JavaScript to the end of your &lt;code&gt;body&lt;/code&gt; element.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;script src=&amp;quot;//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js&amp;quot;&amp;gt;&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;Finally, after the JavaScript is loaded, fire off the &lt;code&gt;initHighlightingOnLoad()&lt;/code&gt; function to add the formatting.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;script&amp;gt;hljs.initHighlightingOnLoad();&amp;lt;/script&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Now that the css and JavaScript is loaded and the OnLoad function is taken care of, we can throw some code at it to be
highlighted.&lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;In a markdown file, any text that is encased in triple backticks will be treated as code upon parsing, the language
can be added after the opening set of backticks.  If the language is not present &lt;em&gt;highlightjs&lt;/em&gt; will make a best guess
to which language it is.&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-markdown&quot;&gt;```javascript
    var s = &amp;quot;JavaScript syntax highlighting&amp;quot;;
    window.alert(s);
    var num = 42;
```
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;The parsed HTML will appear as such.  &lt;em&gt;The class is derived from the language appended to the triple backticks in the above step&lt;/em&gt;
(This will also work on raw HTML written as below, if it is not being parsed from a markdown file)&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-html&quot;&gt;&amp;lt;pre&amp;gt;
    &amp;lt;code class=&amp;quot;language-javascript&amp;quot;&amp;gt;
        var s = &amp;quot;JavaScript syntax highlighting&amp;quot;;
        window.alert(s);
        var num = 42;
    &amp;lt;/code&amp;gt;
&amp;lt;/pre&amp;gt;
&lt;/code&gt;&lt;/pre&gt;
&lt;ul&gt;
&lt;li&gt;The highlighted results of the parsed markdown will appear like this:&lt;/li&gt;
&lt;/ul&gt;
&lt;pre&gt;&lt;code class=&quot;language-javascript&quot;&gt;var s = &amp;quot;JavaScript syntax highlighting&amp;quot;;
window.alert(s);
var num = 42;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;It is really quite simple to implement this powerful code highlighting library, and if the 23 languages included in the
hosted version don&apos;t cover a particular language that you need to highlight you can go to their &lt;a href=&quot;https://highlightjs.org/download/&quot;&gt;download&lt;/a&gt;
page to build a custom version which can include support for any of 176 different languages, which is what I&apos;ll be switching
to as soon as I write my first post that requires highlighting for the twig templating language.&lt;/p&gt;
</description>
<pubDate>Sun, 22 Oct 2017 00:00:00 UTC</pubDate>
</item></channel></rss>