Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:126327 X-Original-To: internals@lists.php.net Delivered-To: internals@lists.php.net Received: from php-smtp4.php.net (php-smtp4.php.net [45.112.84.5]) by qa.php.net (Postfix) with ESMTPS id 57A031A00BC for ; Fri, 7 Feb 2025 11:40:22 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=php.net; s=mail; t=1738928257; bh=bvEKJjfKMWDrpyOILvYOT8SMgMLnLR6JmyYJzal41/Q=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=LV6yCrti5OdMR+iVdInOgfZpRDo4G91/pypXISU/A8G/DR3nbu+3qBH5SbpOfBV2Q ln4Y6fU4YADGWNZjx+658SwPtOG0hF+ZA6wTJ1+PWmenGIv1QrX4eSFZ6CS9pkIJ5f VrZ3IDEoghE6/ANVT6V6B1FnHfe3kX3mid7lu5GNlD13lRQpEnQtVKX+tUMLnGpViz +tMto5BfBjQyqGwFa2DRzSkPvDc6cvKBcQ3BmlGxU36mz02x58bwixMXaQx7aFiqOV 0NRfPNkAkBQKh/hWgpIEjF6jSpOF7TmmoUZYaF6cA7VMa6MSb4uwFWQbC5X3nPOqVp 8HK5CNbHIlDAw== Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 66193180050 for ; Fri, 7 Feb 2025 11:37:36 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=BAYES_50,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,DMARC_PASS, FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=4.0.0 X-Spam-Virus: No X-Envelope-From: Received: from mail-vk1-f181.google.com (mail-vk1-f181.google.com [209.85.221.181]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Fri, 7 Feb 2025 11:37:35 +0000 (UTC) Received: by mail-vk1-f181.google.com with SMTP id 71dfb90a1353d-51f3c823ac1so42043e0c.0 for ; Fri, 07 Feb 2025 03:40:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1738928420; x=1739533220; darn=lists.php.net; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=taGKBBWJT55BBUhq5KzRcaOJYdcQwmw1PtwKU75pIg8=; b=MRj8SSzvNUVIV1/dUlfYy0OH4108Qzbxy8rw0wvvGru8SGXlFyCGyxJ9yMsN3+idf/ 1PDIZBeDvyj2ojdUJiUvF2BfODwCfAm949WJGo9ov/QwsWPFBGAuEWOFgP+LnJo6azZj wYe4fR2leFZPtyO96abmXQ6YZ29xglbF+lrC6V/Kjf6K+wTLnc0KbpSOqZ01q+gO6EW/ HBgBdu118MQBQOSgW8+fUglF5gdVzIRHKoVuoJB9aQfkCCPohka/hALbt59rhFOpx63D QmDxbMjZS1hRXg2t0xlRs0FuZYT34CDK0IU4ob2EOkNFbeSqHghG9G9TxtN+k4bPHgJu 9bpA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1738928420; x=1739533220; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=taGKBBWJT55BBUhq5KzRcaOJYdcQwmw1PtwKU75pIg8=; b=Tu7sOAouWCqQWfRh0Yqm/+WLrW7+iwE1++y0DO3Lmt9tPsIa0TITEaTUzatIEgINb0 fPDPmh7XMs7bPHEj/hE8HX+kKBci+TcUOqXVsMDEGa0If1c/8DUksM14fli1NFKQDr4G 7+LCn+uUGNqF8+wLxVA+CHkyxFKuKVWkogG6HHZYwOJsLvcKVAALH/Zs8tKKQjEJe4oF 30Lsh8RbwZ9Ew3rNkV9tqZZtL+4ufmsVRHj2+5AVLMjdHbON9tNGGdyBRG8iXRzxqYTF pBjoktiR+qPB66CpMv1RbqIG4eE653ECZmS+qs7LjcimZ2fIJ75QGFEg8DPggS9/KpD2 CPnw== X-Forwarded-Encrypted: i=1; AJvYcCXRuoGvkbtFxjvfAmbqrzQX0AZv+ySjZlk6Yq8Lm6nFuwsfmwD9j1wAHa9NMP0xsl0Rj9qojvt7Vnk=@lists.php.net X-Gm-Message-State: AOJu0YylkIY08EOUgVVWqEf/CQYRX7MU14BuxUNrGJCxwS6dd4ao3vDW nf7Dy+B1tHdcE03/t+0iG5o9pIcwPkR6I65J9tOGzWGV7xfGelylpA6qZKurKdUVz5kbYknSbsx puF3Cn0TkxCannr8xYDBAruSTNcc= X-Gm-Gg: ASbGncu1vyU0iWA5CqiO/vvACjANBpB4jn8tKkQ3F0aY6yDQsnnrkAOXIoGHKI9VdvH in5E9tPukJsLuzYe0UfHhYUktP2ZpPplMYVRT4pfBuEfegdK2nq7a6TN2VAtXIEsIvub5pkUB X-Google-Smtp-Source: AGHT+IHD2ytUcDFB1cjEC4gQ5/1IYhQ0rHQv2lLuoLL9V649heNQUklc1NdqU077fPw/mLIM08TURGC6vIEfD8hciRU= X-Received: by 2002:a05:6122:2191:b0:518:91b3:5e37 with SMTP id 71dfb90a1353d-51f2e10befcmr1684221e0c.5.1738928420237; Fri, 07 Feb 2025 03:40:20 -0800 (PST) Precedence: bulk list-help: list-post: List-Id: internals.lists.php.net x-ms-reactions: disallow MIME-Version: 1.0 References: <81ba09d5-d8fa-4c26-8ef0-d4b7bf0de52a@app.fastmail.com> In-Reply-To: <81ba09d5-d8fa-4c26-8ef0-d4b7bf0de52a@app.fastmail.com> Date: Fri, 7 Feb 2025 16:40:09 +0500 X-Gm-Features: AWEUYZmkQKmUr0K8xZi4KbcpiG10etAVA-x5gXvFcbI7rC1IaDDiPX6XGUVrhr0 Message-ID: Subject: Re: [PHP-DEV] RFC: Not Null Assertion Operator To: Rob Landers Cc: Mihail Liahimov <91liahim@gmail.com>, internals@lists.php.net Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable From: ilyaorlov124@gmail.com (MrMeshok) > Hello, > > I feel like that is more of an architecture problem than a programming on= e though. Instead of constantly checking if the conditions are right, use p= hp's type system instead, so it would read more like: > > if ($response instanceof SuccessfulResponse) { > return $response->data->order->quantity; > } > > throw new UnexpectedResponseException($response); > > I'd argue that having an "undefined" aka "null" quantity in a model at al= l is rather strange as that doesn't seem to represent any possible reality = outside of a computer (unless you are dealing with Schrodinger's cat or oth= er quantum effects). > > =E2=80=94 Rob Hi, The thing is I am just a consumer of the API, before implementing I did have a thought about having Successful and Error DTOs, but for me that was more work for the same result. First I need to map JSON to generic Response, then do some checks and map from generic Response to another DTO. And it's not just success and error, there are about 20 response codes and several variations of response you could get. And I absolutely agree about null quantity, some of the objects there have every property nullable, it's insane.