I think it will be easier to understand by giving some examples(you need to execute php commands in command prompt/ terminal)
! is logical operator not and it is defined by php documentation as "!$a has Result TRUE if $a is not TRUE."
php -r "$a=NULL; $b = !$a; var_dump($b);"
returns bool(true)
php -r "$a=''; $b = !$a; var_dump($b);"
returns bool(true)
php -r "$a=array(); $b = !$a; var_dump($b);"
returns bool(true)
php -r "$a=false; $b = !$a; var_dump($b);"
returns bool(true)
php -r "$a=0; $b = !$a; var_dump($b);"
returns bool(true)
php -r "$a=0.0; $b = !$a; var_dump($b);"
returns bool(true)
php -r "$a='0'; $b = !$a; var_dump($b);"
returns bool(true)
While $a === false will be true only if $a is actuall bollean and its value is false(all other previvious examples will be false with ! operator)
php -r "$a=false; $b = $a === false; var_dump($b);"
returns bool(true)
In your example just use not operator ! because you dont need to check type of is_dir result.