« first day (3508 days earlier)      last day (1431 days later) » 
00:00 - 22:0022:00 - 00:00

10:00 PM
yes, this function handles both the POST and the GET request
should i be using separate functions?
per the symfony documentation they typically tie them together, and just use $form->isSubmitted() to check if it's a POST request
it also feels like i've got a ton of dependencies for this function (injected via DI container by the framework)
 
according to PHPStorm, 3 of them are unused
$userService, $api, and $cartService
 
$cartService should be removed, i forgot i abstracted something out
 
@RobertCalove I usually do the same. Otherwise you'll have to redirect back and transfer the POST data somehow or you'll have to also render in the POST method so you'll end up with duplicate code.
 
as for $userService and $api, those are abstracted out by my pseudo code
 
(With the same I mean use 1 function for both)
 
10:04 PM
let me remove those
 
the early return is more about reducing the complexity than the length; it's hard to spot in the middle of the flow
 
public function application(
	Request $request,
	ParameterBagInterface $parameterBag,
	ApplicationService $applicationService,
	SecurityTokenService $securityTokenService
): Response {
	$user = $this->getOrCreateUser();
	$errors = [];

	$securityToken = $securityTokenService->getSecurityToken();

	$application = new Application($parameterBag->get("store_id"), $securityToken['session_id']);
	$form = $this->createForm(ApplicationForm::class, $application, ['user' => $user]);
	$form->handleRequest($request);
so the user sends their application, the code hits a 3rd party API, and if it's successful, it gives me back a URL to redirect the user to
hence the return $this->redirect()
 
@IMSoP Usually I'd agree, however it's a very common pattern though in Symfony so it doesn't really throw me off. Maybe I've just gotten used to it.
 
fair enough
 
the last piece i think i could potentially abstract is
	$application = new Application($parameterBag->get("store_id"), $securityToken['session_id']);
	$form = $this->createForm(ApplicationForm::class, $application, ['user' => $user]);
	$form->handleRequest($request);
into something like

`$this->createApplicationForm()` using a private function in the controller class
public function application(
	Request $request,
	ParameterBagInterface $parameterBag,
	ApplicationService $applicationService,
	SecurityTokenService $securityTokenService
): Response {
	$user = $this->getOrCreateUser();
	$errors = [];

	$securityToken = $securityTokenService->getSecurityToken();

	$form = $this->createApplicationForm($request, $user, $securityToken);

	if ($form->isSubmitted() && $form->isValid()) {
		// use a post-persist event to update the user based on the submitted application
however this has me creating a function with 3 parameters
which can reduce readability or create confusion
 
10:09 PM
        $leaseUrl = null;
        if ($form->isSubmitted() && $form->isValid()) {
            try {
                $leaseUrl = $applicationService->sendApplication($application);
            } catch {
                // etc ...
            }
        }

        if ( isset($leaseUrl) ) {
            return $this->redirect($leaseUrl);
        }
        else {
            return $this->render('checkout/application.html.twig', [
                'form' => $form->createView(),
                'securityToken' => $securityToken,
that feels easier to read to me; but as you say, you get used to patterns
 
gotcha
 
Anyway, I'm off to bed, good night :)
 
good night
thank you for your feedback
 
Np :)
 
10:34 PM
how does the resource type work?
 
magically
:P
 
slightly disturbing...
 
as I understand it, it basically holds a number which some piece of C code can give meaning to later
 
Trying to expand on the typed properties documentation, salathe wants specifics on which types are not supported. Looking at the RFC, it says only callable and void aren't supported.
 
There is no resource type
As in type declaration
 
10:39 PM
ah, so it's just "resource" isn't allowed as a typed property?
I realize "typed property" implies a "data type" but... wtf is resource then
 
it's a type, but it's not available for writing type declarations
 
@Tiffany you can't type anything as resource, not a return type nor argument type as it doesn't exist
It's a "legacy" type
 
you can't say function foo(resource $x){} to only accept resources
 
ah
thanks for clarifying
 
Because it's more or less an integer bound to some special stream handler and it's just eeeer weird
That's why there is a long term project of moving all the resource types to (at least) opaque objects
 
10:42 PM
confusingly, using resource as a type constraint doesn't fail, it just assumes you have a class called resource
 
isn't resource supposed to be reserved?
 
apparently not at the implementation level
 
not sure if I should just list out the types that are supported under typed properties, but it still would be nice to list out what isn't supported... but it needs to be clear...
part of me wants to just throw it in a table
 
int, float, array, bool, string, object, iterable, any interface, any class
 
I'll have to play with the wording, tried typing something up but I didn't like it
 
10:48 PM
(and mixed for PHP 8)
 
?mixed
 
Well yes nullable, but unions also work as of 8
There probably should be section on "declarable types"
 
"Types currently supported are int, float, array, bool, string, object, iterable, any interface name, any class name, self, parent, and nullable types." <- how's that sound?
 
Huh, didn't know about it
I'd say rahter "Any valid type declaration (link to that section) with the exception of callable"
 
that sounds cleaner
 
10:56 PM
As it more future proof to union types and other types being added (like mixed)
 
true
I like specifics, but it does make the docs easier to maintain by linking to a single source
 
also for translators
I still need to go thought another 90odd files for the French translation to update and it looks like most (the 60 I did were at least) are typos in the English Revision
 
@IMSoP referring to your comment, should I call it a "catchable error" or just leave it as an error?
 
Error, capital E, I should think
 
@Girgias I do not envy you
 
10:59 PM
possibly with a link to php.net/manual/en/class.error.php ?
 
@Tiffany still better than when I picked it up 1y1/2 ago and there were around 1000 files to update
(and which needed proper updates not just updating the revision number)
 
"If a typed property is accessed prior to initialization, an Error occurs."?
"a catchable Error occurs." just sounds weird
 
an Error is thrown
 
thanks
 
(try replacing it in your mind with something more familiar like "FileNotFoundException")
 
11:09 PM
do I have the syntax right? <link linkend="functions.arguments.type-declaration">
nevermind, found an example
 
11:21 PM
Blah, I'm going to push it in the morning, I need to double-check that what I've written is good, I think my brain's too tired to determine now.
 
00:00 - 22:0022:00 - 00:00

« first day (3508 days earlier)      last day (1431 days later) »