I have no idea what to do with this pull request that I got from a coworker. It has variable setting and checks for null values that would absolutely be needed if you were writing #PHP code, but are completely superfluous when writing #Twig for #Drupal. If you access a null value, null happens.

Should we be encouraging formal programming practices in twig, or boil all of those lines of code down to just this?

{% set para_id = title|first['#object'].id() %}

@mikemccaffrey
I never allow programming logic in Twig for my Drupal projects. It is too late in the render process and usually can be done best in the entity view mode with proper caching or, if that is not the case, in a preprocessor.
By doing this in PHP allows PHPCS and PHPStan to validate the programming logic.

@absoludo Well, this is a reusable component, and some of the times it is being called the title variable contains a string, and sometimes it contains an array of fields.

In PHP it makes sense to check what sort of value is coming in, but in Twig you can just try to access the nested thing you need and if it exists it will be returned.