CTOlet / yii2-attachments

Yii2 extension for uploading and attaching the files to the models
66 stars 57 forks source link

[Question] Widget AttachmentsTableWithPreview #41

Closed Arekusei closed 8 years ago

Arekusei commented 8 years ago

What is it the hell code?

        $hasFileBehavior = false;
        foreach ($this->model->getBehaviors() as $behavior) {
            if ($behavior->className() == FileBehavior::className()) {
                $hasFileBehavior = true;
            }
        }

Why not used instanceof?

CTOlet commented 8 years ago

Because it works! xD But instanceof is really the right way.

Arekusei commented 8 years ago

It works, but not extendable.

Arekusei commented 8 years ago

And for this code it will be good break foreach after $hasFileBehavior = true.

        $hasFileBehavior = false;
        foreach ($this->model->getBehaviors() as $behavior) {
            if ($behavior instanceof FileBehavior) {
                $hasFileBehavior = true;
                break;
            }
        }
CTOlet commented 8 years ago

Fixed 3ed19c5e2e5b424c7bd0c5dfbff17e49a52f57a7

Arekusei commented 8 years ago

Thank