A short script to remove unused, useless globals in PHP.

Nao

  • Dadman with a boy
  • Posts: 16,077
Re: A short script to remove unused, useless globals in PHP.
« Reply #15, on November 19th, 2013, 09:33 AM »
Oh my, I forgot you liked complex interfaces for small operations... Cf. your analyzer :lol:
So, should I expect you to come by, fork my code and turn it into a giga-script? Then you can do that right now, since it's a WTF file... You don't even have to credit me for the original code, although it'd be nice if you did.
If not, then I'll create my repo all right, but I just don't expect to modify the code any more.

Well, maybe I should also move the 'attic', or even the entire 'other' folder, to another repo. But I've never done that, and don't know if it's easy to do. (Again-- filter-branch. Ouch...)

PS: considering that Wedge will soon modify a few fundamentals of SMF such as folder structure and $theme stuff, are you willing to look into the importer when I do, and make sure it doesn't break..?

TE

  • Posts: 286
Re: A short script to remove unused, useless globals in PHP.
« Reply #16, on November 19th, 2013, 04:36 PM »
Quote from Nao on November 19th, 2013, 09:33 AM
PS: considering that Wedge will soon modify a few fundamentals of SMF such as folder structure and $theme stuff, are you willing to look into the importer when I do, and make sure it doesn't break..?
yep, can have a look but moving folders from one place to another is not a problem for the importer. Modifying the db structure or the content (e.g. BBCodes) is important to know.
Thorsten "TE" Eurich - Former SMF Developer & Converters Guru

Nao

  • Dadman with a boy
  • Posts: 16,077
Re: A short script to remove unused, useless globals in PHP.
« Reply #17, on November 19th, 2013, 05:19 PM »
I made some improvements to the script (it will now find more unused vars than before), so I guess it makes sense to use git for that; I'll be moving to a github repo so that I can commit if I have other things to update.

This will be my first 'real' use of github though, and I'm wondering if it's worth hiding my e-mail address over there. Also, using the antispam feature, my e-mail address starts with "Naowe@" (my old user-name), when it's been renamed for quite a long time to "Nao@"... Dunno why it's still using that old name. Anyone knows how to fix, maybe..?

PS: let's just say it's going to be... well, my very own github tutorial.
Re: A short script to remove unused, useless globals in PHP.
« Reply #18, on November 20th, 2013, 10:54 AM »
It's all turned into a really, really nice little script by now. It does all the changes for me, too, if I ask nicely. I'm currently in the process of checking all files manually, it's all good. Only one single false-positive so far, and that's because the global keyword was in comments, so I added an extra check for that (it won't work in multi-line comments, though.)

And I really should commit it! But I have yet to receive an answer from github, re: my account/e-mail problems. I don't want to have to re-create my repo later, so... Waiting for now.
Re: A short script to remove unused, useless globals in PHP.
« Reply #19, on November 20th, 2013, 05:29 PM »Last edited on November 20th, 2013, 05:44 PM
(Yay, first Google result on selected keywords from the post title. SEO isn't as bad as I thought :D)

Current script size is 120 lines, lol.
The next update will be MIT licensed, then. I'm still waiting for github to answer my e-mail, or anyone really.

SMF people will love it[1], because of the auto-fixer, and it had 100% accuracy on the Wedge codebase, I didn't have to do any last-minute fixes apart from one in ManagePlugins which helped strengthen the script even further.
Heck, I could even run the thing myself on SMF 2.1, and push that...
 1. Well, everyone but Arantor, of course.

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,668
A confident man keeps quiet.whereas a frightened man keeps talking, hiding his fear.

Nao

  • Dadman with a boy
  • Posts: 16,077
Re: A short script to remove unused, useless globals in PHP.
« Reply #21, on November 20th, 2013, 10:55 PM »
Right now, the only false positives that can be found are:

Code: [Select]
function foobar() {
/* This is a comment.
global $something;
*/
return;
}

As well as, hmm...

Code: [Select]
function foobar() {
echo '
global $something;';
}

There may be other situations where it'll find false positives, but they'll probably be variations on the ones above.
Basically, I could try and remove comments, I'm doing it on Wess after all, but I'll have to restore them before fixing the files, and I can't bother for now. As for quotes, since there are single quotes and double quotes and heredoc and nowdoc, and... I don't know if I'll ever bother about that, unless I can find a script that removes these easily for me. (Keeping in mind they must also be restored.)

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,668

Nao

  • Dadman with a boy
  • Posts: 16,077

live627

  • Should five per cent appear too small / Be thankful I don't take it all / 'Cause I'm the taxman, yeah I'm the taxman
  • Posts: 1,668

Nao

  • Dadman with a boy
  • Posts: 16,077
Re: A short script to remove unused, useless globals in PHP.
« Reply #26, on November 23rd, 2013, 12:09 AM »
Quote from Nao on November 19th, 2013, 05:19 PM
This will be my first 'real' use of github though, and I'm wondering if it's worth hiding my e-mail address over there. Also, using the antispam feature, my e-mail address starts with "Naowe@" (my old user-name), when it's been renamed for quite a long time to "Nao@"... Dunno why it's still using that old name. Anyone knows how to fix, maybe..?
I have yet to receive an answer from github, which is surprising, given that my earlier support request didn't involve a bug report and was answered within a few hours.

This means that I'm still unable to launch the repo. Although I could just give up on the idea of using the website's merging feature at all. They have a method to do the merges locally, so I could possibly fetch pull requests, then either rebase or merge them, whatever, and then push them to the official repo. That would, effectively, make my local repo the 'authoritative' one, with the github repo being just a 'backup' of sorts, I guess. And it also means I'm the only merger around forever, at least until I'm ready for 'more'.

emanuele

  • Posts: 125
Re: A short script to remove unused, useless globals in PHP.
« Reply #27, on November 23rd, 2013, 02:32 PM »
Where can you see the email at github?

Sign-off?
If so, you have to change the config of your local git (global config or local config depending on what you want to obtain).
And the old commits do not change unless you rewrite the history resigning all of them (once I found a trick to do that, but last time I tried to find it again I wasn't able to... :().

Nao

  • Dadman with a boy
  • Posts: 16,077
Re: A short script to remove unused, useless globals in PHP.
« Reply #28, on November 23rd, 2013, 03:19 PM »
No. Shows up when doing site operations like merging pull requests or creating a repo.
I'm aware of how settings work don't worry ;)
O just want the website to follow my own personal settings but they won't. They only pass valid emails to git. Or you have to use their no spam email, but as I said, it's buggy, and github is not giving feedback.

Re history rewrite, it's done through git filter-branch. There's a script for email rewriting in the official online git book (git-scm.com iirc), and stackoverflow of course.
Re: A short script to remove unused, useless globals in PHP.
« Reply #29, on November 24th, 2013, 11:26 AM »
So, I received an answer from GH shortly after my last post here. :)
- They fixed my username,
- They're working on a fix for everyone who changes their username,
- They're looking into whether it's possible to choose your commit name when doing web merges.

Good!

In the meantime, I made some tests on a GH repo, and have come to these conclusions:
- (This, I already knew but it's important to point out) You can set your commit e-mail per-repo ('local') or for all repos ('global'), so if you want to change e-mails between repos, it's easy as pie, and if they're all in your GH account, then GH will always show your commits as yours.
- Antispam e-mails used when web merging at GH are really, really noreply e-mails. That is, e-mails to these aren't redirected to your actual registered e-mail, so... Hmm, I don't know, it can be a good thing, or a bad thing.
- TortoiseGit statistics only care about the user name. If my user name is 'Nao', whatever the commit e-mail is, the stats page will merge everything together into the Nao entry. Good.
- My commit e-mail at GH is indeed fixed.
- You can 'force' GH to commit using your user name by simply removing your name. I've chosen to put it into my 'Work' box, it works very well, as it shows my name in small characters right below my user name, and right above my location. That's, really, the best place I could have put it into, eh. Of course I can't say 'Wedge' in my work box, but... Whatever. People who come to my account know what I'm working on, really. After all, Wedge will soon be on my repo list, so, whatever... :P

All in all, good news. I'll get started on this unused-globals.php repo, using my usual commit e-mail (nao@wedge --> and yes, you can add the obvious TLD to the domain, and it'll redirect to my e-mail address. For now, at least.)