Skip to content
This repository was archived by the owner on Feb 15, 2023. It is now read-only.

Fix local #5

Merged
merged 14 commits into from
Mar 7, 2018
Merged

Fix local #5

merged 14 commits into from
Mar 7, 2018

Conversation

Crell
Copy link
Contributor

@Crell Crell commented Mar 6, 2018

The current code doesn't work properly in a local environment, as the detection to determine if the code is running on build or live is buggy. That's easy enough to fix, but while I was at it I figured what the hell, let's test this puppy!

So, here's a major overhaul and cleanup that includes a bunch of tests to make sure it all works.

@jepster
Copy link

jepster commented Mar 6, 2018

Writing tests when working on a (testable) piece of code, is the correct approach. thumbs up

Tested this code on my local environment and it seems to work. I have some objections, which I like to share with you Larry.

Is it necessary to work with this PHP function, instead of a Symfony kernel event listener? Also it seems a bit uncommon to set the $_SESSION variable directly, without the session component from Symfony (http://symfony.com/doc/current/components/http_foundation/sessions.html).

Your tests do not have a return type defined. As of PHP 7, you can define that:

public function testAppEnvAlreadySetInServer():void -> Like you have done in mapPlatformShEnvironment().

The mapPlatformShEnvironment() function is a mix of if-cases and a switch table. You are only comparing and mapping here. Have you thought of using lookup tables like in the following JavaScript code example?

The following example shows via JavaScript, how a long function with if-cases can be shortened and made more readable by a lookup table.

function doSomething(a) {  
  if (a === 'x') {  
    doX();  
  } else if (a === 'y') {  
    doY();  
  } else {  
    doZ();  
  }  
}  

Will become this:

function doSomething(a) {  
  var lookup = { x: doX, y: doY }, def = doZ;  
  lookup[a] ? lookup[a]() : def(); 
} 

@jepster
Copy link

jepster commented Mar 6, 2018

Another objection: do you like to squash your Git commits to 1 commit for easier Git history readability with the GitHub issue ID in it?: https://mobilefish.de/git-swipe-log-branch-history-and-create-just-one-commit

@Crell
Copy link
Contributor Author

Crell commented Mar 7, 2018

Thanks, @jepster.

  1. I rarely squash commits. I sometimes will do a history cleanup on a branch to remove "fixup" commits but I like seeing the steps involved, especially in a case like this where there's several things going on in one branch, but not all in one commit.

  2. A Symfony kernel event is too late for this code to run. It needs to run before Symfony initializes itself or the container, which means autoload is the only place for it to hook in.

  3. The code isn't touching $_SESSION. It's modifying $_SERVER. That's because @dunglas indicated that was better in Fix Postgres support. Cleanup the code. #2 as that's what Symfony prefers to read from, and I'm inclined to take his word for it.

  4. I wasn't sure what the convention these days is for test methods and returns. I'm all for typing all the things, though, so I'll add them.

  5. I've used maps in the past quite effectively, but I don't think they fit here. The one switch statement I inherited from @dunglas in Fix Postgres support. Cleanup the code. #2, and I think it does fit in this case. The reset is just normal boring conditional control logic. There's fairly little mapping going on here.

@Crell Crell merged commit 8f992eb into master Mar 7, 2018
@Crell Crell deleted the fix-local branch March 7, 2018 19:39
@Crell
Copy link
Contributor Author

Crell commented Mar 7, 2018

You made me a PR I couldn't refuse...

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants