Please use Yoda conditions:

`if (ClassMetadataInfo::MANY_TO_MANY === $mapping['type']) {`

Also, avoid non-strict comparison (`==`) and always use `===` where possible