The if condition makes little sense because if the itemId was invalid it would have already crashed at

`unsigned maxPerSlot = itemManager->getItem(itemId)->getMaxPerSlot();`

I'd say introduce the `item` variable earlier. As for the check, I guess we should prevent inserting non-existing items (so return `amount` when `item` is 0).