protected function cleanupObj($obj, $isMetaData)
    {
        if (is_null($obj)) {
            return;
        }

        if (is_array($obj)) {
            $clean = [];

            foreach ($obj as $key => $value) {
                $clean[$key] = $this->shouldFilter($key, $isMetaData) ? '[FILTERED]' : $this->cleanupObj($value, $isMetaData);
            }

            return $clean;
        }

        if (is_string($obj)) {
            return (function_exists('mb_detect_encoding') && !mb_detect_encoding($obj, 'UTF-8', true)) ? utf8_encode($obj) : $obj;
        }

        if (is_object($obj)) {
            return $this->cleanupObj(json_decode(json_encode($obj), true), $isMetaData);
        }

        return $obj;
    }
protected function cleanupObj($obj, $isMetaData)
    {
        if (is_null($obj)) {
            return;
        }

        if (is_array($obj)) {
            $clean = [];

            foreach ($obj as $key => $value) {
                $clean[$key] = $this->shouldFilter($key, $isMetaData) ? '[FILTERED]' : $this->cleanupObj($value, $isMetaData);
            }

            return $clean;
        }

        if (is_string($obj)) {
            return (function_exists('mb_detect_encoding') && !mb_detect_encoding($obj, 'UTF-8', true)) ? utf8_encode($obj) : $obj;
        }

        if (is_object($obj)) {
            return $this->cleanupObj(json_decode(json_encode($obj), true), $isMetaData);
        }

        return $obj;
    }
protected function cleanupObj ( $ obj , $ isMetaData ) { if ( is_null ( $ obj ) ) { return ; } if ( is_array ( $ obj ) ) { $ clean = [ ] ; foreach ( $ obj as $ key => $ value ) { $ clean [ $ key ] = $ this -> shouldFilter ( $ key , $ isMetaData ) ? '[FILTERED]' : $ this -> cleanupObj ( $ value , $ isMetaData ) ; } return $ clean ; } if ( is_string ( $ obj ) ) { return ( function_exists ( 'mb_detect_encoding' ) && ! mb_detect_encoding ( $ obj , 'UTF-8' , true ) ) ? utf8_encode ( $ obj ) : $ obj ; } if ( is_object ( $ obj ) ) { return $ this -> cleanupObj ( json_decode ( json_encode ( $ obj ) , true ) , $ isMetaData ) ; } return $ obj ; }
Cleanup the given object.

@param mixed $obj        the data to cleanup
@param bool  $isMetaData if it is meta data

@return array|null
Cleanup the given object .