src/Uri.php
public function getPort()
    {
        switch (mb_strtolower($this->getScheme())) {
            case 'http':
                if ($this->port != 80) {
                    return $this->port;
                }
                break;
            case 'https':
                if ($this->port != 443) {
                    return $this->port;
                }
                break;
            default:
                return $this->port ?? null;
        }

        return null;
    }
public function getPort()
    {
        switch (mb_strtolower($this->getScheme())) {
            case 'http':
                if ($this->port != 80) {
                    return $this->port;
                }
                break;
            case 'https':
                if ($this->port != 443) {
                    return $this->port;
                }
                break;
            default:
                return $this->port ?? null;
        }

        return null;
    }
Retrieve the port component of the URI.

If a port is present, and it is non-standard for the current scheme,
this method MUST return it as an integer. If the port is the standard port
used with the current scheme, this method SHOULD return null.

If no port is present, and no scheme is present, this method MUST return
a null value.

If no port is present, but a scheme is present, this method MAY return
the standard port for that scheme, but SHOULD return null.

@return null|int The URI port.