<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Michael Lueckl</title>
    <description>The latest articles on DEV Community by Michael Lueckl (@mlueckl).</description>
    <link>https://dev.to/mlueckl</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F26516%2F376bcb77-4715-43bc-af97-5277c377ba5d.jpg</url>
      <title>DEV Community: Michael Lueckl</title>
      <link>https://dev.to/mlueckl</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mlueckl"/>
    <language>en</language>
    <item>
      <title>Best Practice - Check if property exist and assign</title>
      <dc:creator>Michael Lueckl</dc:creator>
      <pubDate>Tue, 07 Aug 2018 17:56:51 +0000</pubDate>
      <link>https://dev.to/mlueckl/best-practice---check-if-property-exist-and-assign--1nli</link>
      <guid>https://dev.to/mlueckl/best-practice---check-if-property-exist-and-assign--1nli</guid>
      <description>&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;from time to time you might need to assign properties or similar to variables and in some cases some don't exist.&lt;/p&gt;

&lt;p&gt;In PHP and most other languages it's pretty straightforward to check for example:&lt;/p&gt;

&lt;p&gt;~~~~&lt;del&gt;&lt;/del&gt; php&lt;br&gt;
if(isset($issue['samples']))&lt;br&gt;
    $i-&amp;gt;samples = $issue['samples'];&lt;br&gt;
~~~~&lt;del&gt;&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;This is also ok for multiple cases:&lt;/p&gt;

&lt;p&gt;~~~~&lt;del&gt;&lt;/del&gt; php&lt;br&gt;
if(isset($issue['samples']))&lt;br&gt;
    $i-&amp;gt;samples = $issue['samples'];&lt;/p&gt;

&lt;p&gt;if(isset($issue['summary']))&lt;br&gt;
    $i-&amp;gt;summary = $issue['summary'];&lt;/p&gt;

&lt;p&gt;if(isset($issue['property_names']))&lt;br&gt;
    $i-&amp;gt;property_names = $issue['property_names'];&lt;/p&gt;

&lt;p&gt;if(isset($issue['description']))&lt;br&gt;
    $i-&amp;gt;description = $issue['description'];&lt;/p&gt;

&lt;p&gt;if(isset($issue['count']))&lt;br&gt;
    $i-&amp;gt;count = $issue['count'];&lt;br&gt;
~~~~&lt;del&gt;&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;And at some point I came up with inline if's which makes it easier to write/read and maintain.&lt;/p&gt;

&lt;p&gt;~~~~&lt;del&gt;&lt;/del&gt; php&lt;br&gt;
$i-&amp;gt;samples = (isset($issue['samples']) ? $issue['samples'] : null);&lt;br&gt;
$i-&amp;gt;summary = (isset($issue['summary']) ? $issue['summary'] : null);&lt;br&gt;
$i-&amp;gt;property_names = (isset($issue['property_names']) ? $issue['property_names'] : null);&lt;br&gt;
$i-&amp;gt;description = (isset($issue['description']) ? $issue['description'] : null);&lt;br&gt;
$i-&amp;gt;count = (isset($issue['count']) ? $issue['count'] : null);&lt;br&gt;
~~~~&lt;del&gt;&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;But I feel there might be other and better way's of handling this.&lt;/p&gt;

&lt;p&gt;Here the full example with a foreach-loop:&lt;/p&gt;

&lt;p&gt;~~~~&lt;del&gt;&lt;/del&gt; php&lt;br&gt;
foreach($data['quality_issues']['data'] as $issue){&lt;br&gt;
    if($issue['property_names'] != 'product_category'){&lt;br&gt;
        print_r($issue);&lt;br&gt;
        $i = new QualityIssue();&lt;br&gt;
        $i-&amp;gt;samples = (isset($issue['samples']) ? $issue['samples'] : null);&lt;br&gt;
        $i-&amp;gt;summary = (isset($issue['summary']) ? $issue['summary'] : null);&lt;br&gt;
        $i-&amp;gt;property_names = (isset($issue['property_names']) ? $issue['property_names'] : null);&lt;br&gt;
        $i-&amp;gt;description = (isset($issue['description']) ? $issue['description'] : null);&lt;br&gt;
        $i-&amp;gt;count = (isset($issue['count']) ? $issue['count'] : null);&lt;br&gt;
        $i-&amp;gt;error = (isset($issue['error']) ? $issue['error'] : null);&lt;br&gt;
        $i-&amp;gt;name = (isset($issue['name']) ? $issue['name'] : null);&lt;br&gt;
        $i-&amp;gt;type = (isset($issue['type']) ? $issue['type'] : null);&lt;br&gt;
        $i-&amp;gt;level = (isset($issue['level']) ? $issue['level'] : null);&lt;br&gt;
        $i-&amp;gt;category = (isset($issue['category']) ? $issue['category'] : null);&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    array_push($partner-&amp;gt;catalog-&amp;gt;quality_issues, $i);
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;br&gt;
~~~~&lt;del&gt;&lt;/del&gt;&lt;/p&gt;

&lt;p&gt;Maybe I'm overthinking this and the inline if is already the "perfect" solution (as if this exists :)) but I would like to hear from you how you normally handle this and if you came up with good practices that might help to improve this.&lt;/p&gt;

&lt;p&gt;Cheers,&lt;br&gt;
Michael&lt;/p&gt;

&lt;p&gt;CONCLUSION:&lt;/p&gt;

&lt;p&gt;Really appreciate the great feedback in the comments and wanted to describe the solution which I found most suitable suggested by &lt;a class="mentioned-user" href="https://dev.to/franco"&gt;@franco&lt;/a&gt; Traversaro:&lt;/p&gt;

&lt;p&gt;~~~~&lt;del&gt;&lt;/del&gt; php&lt;br&gt;
class QualityIssue{&lt;br&gt;
    public static function fromArray(array $source) : self&lt;br&gt;
    {&lt;br&gt;
        $i = new self(); &lt;br&gt;
        foreach ($source as $property =&amp;gt; $value) {&lt;br&gt;
            $i-&amp;gt;{$property} = $value;&lt;br&gt;
        }&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;    return $i;
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;}&lt;/p&gt;

&lt;p&gt;foreach($data['quality_issues']['data'] as $issue){&lt;br&gt;
    if($issue['property_names'] != 'product_category'){&lt;br&gt;
        array_push($partner-&amp;gt;catalog-&amp;gt;quality_issues, QualityIssue::fromArray($issue));&lt;br&gt;
    }&lt;br&gt;
}&lt;br&gt;
~~~~&lt;del&gt;&lt;/del&gt;&lt;/p&gt;

</description>
      <category>php</category>
      <category>programming</category>
      <category>style</category>
      <category>syntax</category>
    </item>
    <item>
      <title>Suggestion to improve dev.to user feed</title>
      <dc:creator>Michael Lueckl</dc:creator>
      <pubDate>Thu, 12 Jul 2018 19:52:38 +0000</pubDate>
      <link>https://dev.to/mlueckl/suggestion-to-improve-devto-user-feed-9b4</link>
      <guid>https://dev.to/mlueckl/suggestion-to-improve-devto-user-feed-9b4</guid>
      <description>

&lt;p&gt;Hi all,&lt;/p&gt;

&lt;p&gt;this is my first post and so far I was just playing silent reader, giving out hearts for great posts and saving the good stuff for late nights 😄&lt;br&gt;
This portal is so great and I'm really happy to have found it!&lt;/p&gt;

&lt;p&gt;Something that I noticed and that somewhat bothers me a bit is the &lt;b&gt;User Feed&lt;/b&gt;, initially, I thought it's based on &lt;b&gt;my tags&lt;/b&gt; but this is not the case.&lt;/p&gt;

&lt;p&gt;Don't get me wrong, I love to explore new things but I think it would make more sense to have the &lt;b&gt;Feed&lt;/b&gt; only show posts based on my followed tags so that I get all relevant posts based on my interests without distraction of other big topics, I'm looking at you "Web development".&lt;br&gt;
Don't freak out web dev lovers 😛 but in my case, most of the time I'm not too interested in most web dev topics. &lt;br&gt;
Because this is obviously very popular, my feed is always flooded with those posts.&lt;/p&gt;

&lt;p&gt;What I have in mind would be, rename "Feed" &amp;gt;&amp;gt; "TOP"/"Top Posts" and have a new "Feed" based on the users followed tags.&lt;/p&gt;

&lt;p&gt;It would even make sense to have cross-references of top posts based on tags, the user currently would not see in his feed. &lt;br&gt;
It could show up like a "promoted" post in the user feed, something like "This could be interesting for you based on 'tag', 'tag'"&lt;/p&gt;

&lt;p&gt;Not sure if this was ever considered or discussed, wasn't in the first search results, but I thought I bring it up as I feel this would be something not only I would appreciate.&lt;br&gt;
Let me know if I didn't yet had have enough coffee and simply oversaw the option to set this up my self 😜&lt;/p&gt;

&lt;p&gt;Thanks again for this great portal and of course for all the great people creating awesome posts!&lt;/p&gt;

&lt;p&gt;Cheers,&lt;br&gt;
Michael&lt;/p&gt;


</description>
      <category>devto</category>
      <category>suggestion</category>
    </item>
  </channel>
</rss>
