private function __getFileName($fileInfo, EntityInterface $entity, $id = 0)
    {
        if (!file_exists(Configure::read('Attachments.path') . $entity->source() . '/' . $entity->id . '/' . $fileInfo['basename'])) {
            return $fileInfo;
        }
        $fileInfo['basename'] = $fileInfo['filename'] . ' (' . ++$id . ').' . $fileInfo['extension'];
        return $this->__getFileName($fileInfo, $entity, $id);
    }
private function __getFileName($fileInfo, EntityInterface $entity, $id = 0)
    {
        if (!file_exists(Configure::read('Attachments.path') . $entity->source() . '/' . $entity->id . '/' . $fileInfo['basename'])) {
            return $fileInfo;
        }
        $fileInfo['basename'] = $fileInfo['filename'] . ' (' . ++$id . ').' . $fileInfo['extension'];
        return $this->__getFileName($fileInfo, $entity, $id);
    }
private function __getFileName ( $ fileInfo , EntityInterface $ entity , $ id = 0 ) { if ( ! file_exists ( Configure :: read ( 'Attachments.path' ) . $ entity -> source ( ) . '/' . $ entity -> id . '/' . $ fileInfo [ 'basename' ] ) ) { return $ fileInfo ; } $ fileInfo [ 'basename' ] = $ fileInfo [ 'filename' ] . ' (' . ++ $ id . ').' . $ fileInfo [ 'extension' ] ; return $ this -> __getFileName ( $ fileInfo , $ entity , $ id ) ; }
recursive method to increase the filename in case the file already exists

@param string $fileInfo Array of information about the file
@param EntityInterface $entity Entity
@param string $id counter varibale to extend the filename
@return array
recursive method to increase the filename in case the file already exists