Subclass on submenu links

Permalink
Hello everybody,

I made a custom navigation block which uses classes on the links.
Now it also applies the class on the child which doesn't have any subpages anymore.

How can I make sure that all the childs without submenu's don't get the class ?

Here is my code :
<?php
echo '<ul class="clearlist">'; //opens the top-level menu
foreach ($navItems as $ni) {
   echo '<li class="' . $ni->classes . '">'; //opens a nav item
   echo '<a href="' . $ni->url . '" target="' . $ni->target . '" class="'. $sClass . $ni->classes . '">' 
         . $ni->name;
         if($ni->hasSubmenu) { 
            echo '<i class="fa fa-angle-down"></i>'; 
         }
   echo '</a>';
   if ($ni->hasSubmenu) {
      echo '<ul class="mn-sub">'; //opens a dropdown sub-menu
   } else {
      echo '</li>'; //closes a nav item
      echo str_repeat('</ul></li>', $ni->subDepth); //closes dropdown sub-menu(s) and their top-level nav item(s)