code: private function find(array &$list, $oid, StockUnitInterface $unit)
      {
          if (!isset($list[$oid])) {
              return false;
          }
  
          // Non persisted search
          if (null === $unit->getId()) {
              return array_search($unit, $list[$oid], true);
          }
  
          // Persisted search
          /** @var StockUnitInterface $u */
          foreach ($list[$oid] as $index => $u) {
              if ($u->getId() == $unit->getId()) {
                  return $index;
              }
          }
  
          return false;
      }
docs: Finds the unit into the given list for the given object identifier.
  
  @param array              $list
  @param string             $oid
  @param StockUnitInterface $unit
  
  @return bool|false|int|string