Git Autoupdater
Clash Royale CLAN TAG#URR8PPP
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty margin-bottom:0;
up vote
1
down vote
favorite
At my office we have an internal monitoring tool we use on customer systems to monitor various vitals and notify us via Slack. Our Lead Dev and Chief Architect are very paranoid about Git, and outright refuse to put it on customer systems, however they still like the idea of using it for development.
So I created an autoupdater script for our monitoring tool that allows us to push changes to git, and have the tool auto-update from the repo without having to put git on systems.
It's written in PHP as this is the primary language in use at the office (specifically 5.3.3, although one of our devs is currently writing a technical specification for updating to 5.6), and it uses GitLab's api on our own internal gitlab host.
I've also spoofed a few details for privacy reasons, for example the config file is not called config.conf
, and the service is not called tool
.
<?php
//Until config can be loaded, assume _LOC is the directory of this script
$_LOC = realpath(dirname(__FILE__)).'/';
//Look for config file
echo "Searching for ".$_LOC."config/config.confn";
if (!file_exists($_LOC.'config/config.conf'))
echo "Searching for ".$_LOC."config/config.template.confn";
if (!file_exists($_LOC.'config/config.template.conf'))
exit('Config file does not exist and template was not found!');
//Create config from template
echo "Template exists, creating config filen";
copy($_LOC.'config/config.template.conf', $_LOC.'config/config.conf');
//Imports
require($_LOC.'lib/functions.php');
require($_LOC.'config/config.conf');
require('/etc/casper/defaults.conf');
if ($_DEBUG) echo "Starting update checkn";
if ($_DEBUG) echo "Fetching commitsn";
//Fetch all commits for set branch, default sorted by newest first
$commitsjson = gitlab_fetch("projects/$_GIT_ID/repository/commits", array('ref' => $_GIT_BRANCH));
$commits = json_decode($commitsjson);
$lastcommit = $commits[0];
$lastcommit = $lastcommit->id;
if ($_DEBUG) echo "Latest commit is ".$lastcommit."n";
if ($lastcommit !== $_UPDATE_SHA)
if ($_DEBUG) echo "But current update is ".$_UPDATE_SHA."nUpdating...";
//Fetch recursive tree of all files and directories
$filejson = gitlab_fetch("projects/$_GIT_ID/repository/tree", array('recursive' => 'true', 'ref' => $_GIT_BRANCH));
$fileinfo = json_decode($filejson);
//Create backup directory
$bakdate = date('Ymd');
$bakloc = $_LOC.'bak'.$bakdate.'/';
mkdir($bakloc);
$files = array();
$dirs = array();
//Format each file to url to fetch file contents and filter directories to separate array
foreach($fileinfo as $file)
if ($file->type == "blob")
$files[$file->path] = "projects/$_GIT_ID/repository/files/".$file->path;
else if ($file->type == "tree")
$dirs = $file->path;
//Create directories
foreach($dirs as $dir)
if ($_DEBUG) echo "Creating directory $dirn";
if (!file_exists($_LOC.$dir)) mkdir($_LOC.$dir);
else mkdir($bakloc.$dir);
//Fetch files
foreach($files as $path => $fileapi)
if ($_DEBUG) echo "Fetching $pathn";
//Fetch json
$fileraw = gitlab_fetch($fileapi, array('ref' => $_GIT_BRANCH));
$fileobj = json_decode($fileraw);
//If content is set, file was successfully pulled
if (isset($fileobj->content))
//content is provided in base64, need to decode
$filecontent = base64_decode($fileobj->content);
if ($_DEBUG) echo "Fetched ".strlen($fileobj->content)." bytes, decoded into ".strlen($filecontent)." bytesn";
//Backup file if it already exists
if (file_exists($_LOC.$path))
if ($_DEBUG) echo "Backing up $_LOC$path to $bakloc$pathn";
copy($_LOC.$path, $bakloc.$path);
if ($_DEBUG) echo "Overwriting $_LOC$pathn";
file_put_contents($_LOC.$path, $filecontent);
if ($_DEBUG) echo "Donen";
//If message is set, an error was returned
else if (isset($fileobj->message))
//Output the error
if ($_DEBUG) echo "Failed to download $path with response ".$fileobj->message."n";
//Update the commit hash
if ($_DEBUG) echo "Updating commit hashn";
file_put_contents($_LOC.'config/update-hash', $lastcommit);
if ($_DEBUG) echo "Restarting tool...n";
//Log restart in slack, and restart service
slack_pretty_log('Tool Updated', "Tool $_VERSION has updated! Restarting...", 'good');
$output = shell_exec('sudo /etc/init.d/tool restart 2>&1');
if ($_DEBUG) echo $output;
//End
else
if ($_DEBUG) echo "No new updatesn";
Functions such as slack_pretty_log
and gitlab_fetch
are defined externally and use the respective APIs, and any variables beginning with underscores (such as $_DEBUG
and $_GIT_BRANCH
) are defined in the config file.
I'm mainly interested in feedback on the flow of the logic itself, as well as naming conventions (which I admittedly didn't do a great job of adhering to) and comments.
This is a standalone script designed to run once per day on a cronjob, which is why it has a lot of logic outside of any functions or classes.
linux php5 git
add a comment |Â
up vote
1
down vote
favorite
At my office we have an internal monitoring tool we use on customer systems to monitor various vitals and notify us via Slack. Our Lead Dev and Chief Architect are very paranoid about Git, and outright refuse to put it on customer systems, however they still like the idea of using it for development.
So I created an autoupdater script for our monitoring tool that allows us to push changes to git, and have the tool auto-update from the repo without having to put git on systems.
It's written in PHP as this is the primary language in use at the office (specifically 5.3.3, although one of our devs is currently writing a technical specification for updating to 5.6), and it uses GitLab's api on our own internal gitlab host.
I've also spoofed a few details for privacy reasons, for example the config file is not called config.conf
, and the service is not called tool
.
<?php
//Until config can be loaded, assume _LOC is the directory of this script
$_LOC = realpath(dirname(__FILE__)).'/';
//Look for config file
echo "Searching for ".$_LOC."config/config.confn";
if (!file_exists($_LOC.'config/config.conf'))
echo "Searching for ".$_LOC."config/config.template.confn";
if (!file_exists($_LOC.'config/config.template.conf'))
exit('Config file does not exist and template was not found!');
//Create config from template
echo "Template exists, creating config filen";
copy($_LOC.'config/config.template.conf', $_LOC.'config/config.conf');
//Imports
require($_LOC.'lib/functions.php');
require($_LOC.'config/config.conf');
require('/etc/casper/defaults.conf');
if ($_DEBUG) echo "Starting update checkn";
if ($_DEBUG) echo "Fetching commitsn";
//Fetch all commits for set branch, default sorted by newest first
$commitsjson = gitlab_fetch("projects/$_GIT_ID/repository/commits", array('ref' => $_GIT_BRANCH));
$commits = json_decode($commitsjson);
$lastcommit = $commits[0];
$lastcommit = $lastcommit->id;
if ($_DEBUG) echo "Latest commit is ".$lastcommit."n";
if ($lastcommit !== $_UPDATE_SHA)
if ($_DEBUG) echo "But current update is ".$_UPDATE_SHA."nUpdating...";
//Fetch recursive tree of all files and directories
$filejson = gitlab_fetch("projects/$_GIT_ID/repository/tree", array('recursive' => 'true', 'ref' => $_GIT_BRANCH));
$fileinfo = json_decode($filejson);
//Create backup directory
$bakdate = date('Ymd');
$bakloc = $_LOC.'bak'.$bakdate.'/';
mkdir($bakloc);
$files = array();
$dirs = array();
//Format each file to url to fetch file contents and filter directories to separate array
foreach($fileinfo as $file)
if ($file->type == "blob")
$files[$file->path] = "projects/$_GIT_ID/repository/files/".$file->path;
else if ($file->type == "tree")
$dirs = $file->path;
//Create directories
foreach($dirs as $dir)
if ($_DEBUG) echo "Creating directory $dirn";
if (!file_exists($_LOC.$dir)) mkdir($_LOC.$dir);
else mkdir($bakloc.$dir);
//Fetch files
foreach($files as $path => $fileapi)
if ($_DEBUG) echo "Fetching $pathn";
//Fetch json
$fileraw = gitlab_fetch($fileapi, array('ref' => $_GIT_BRANCH));
$fileobj = json_decode($fileraw);
//If content is set, file was successfully pulled
if (isset($fileobj->content))
//content is provided in base64, need to decode
$filecontent = base64_decode($fileobj->content);
if ($_DEBUG) echo "Fetched ".strlen($fileobj->content)." bytes, decoded into ".strlen($filecontent)." bytesn";
//Backup file if it already exists
if (file_exists($_LOC.$path))
if ($_DEBUG) echo "Backing up $_LOC$path to $bakloc$pathn";
copy($_LOC.$path, $bakloc.$path);
if ($_DEBUG) echo "Overwriting $_LOC$pathn";
file_put_contents($_LOC.$path, $filecontent);
if ($_DEBUG) echo "Donen";
//If message is set, an error was returned
else if (isset($fileobj->message))
//Output the error
if ($_DEBUG) echo "Failed to download $path with response ".$fileobj->message."n";
//Update the commit hash
if ($_DEBUG) echo "Updating commit hashn";
file_put_contents($_LOC.'config/update-hash', $lastcommit);
if ($_DEBUG) echo "Restarting tool...n";
//Log restart in slack, and restart service
slack_pretty_log('Tool Updated', "Tool $_VERSION has updated! Restarting...", 'good');
$output = shell_exec('sudo /etc/init.d/tool restart 2>&1');
if ($_DEBUG) echo $output;
//End
else
if ($_DEBUG) echo "No new updatesn";
Functions such as slack_pretty_log
and gitlab_fetch
are defined externally and use the respective APIs, and any variables beginning with underscores (such as $_DEBUG
and $_GIT_BRANCH
) are defined in the config file.
I'm mainly interested in feedback on the flow of the logic itself, as well as naming conventions (which I admittedly didn't do a great job of adhering to) and comments.
This is a standalone script designed to run once per day on a cronjob, which is why it has a lot of logic outside of any functions or classes.
linux php5 git
add a comment |Â
up vote
1
down vote
favorite
up vote
1
down vote
favorite
At my office we have an internal monitoring tool we use on customer systems to monitor various vitals and notify us via Slack. Our Lead Dev and Chief Architect are very paranoid about Git, and outright refuse to put it on customer systems, however they still like the idea of using it for development.
So I created an autoupdater script for our monitoring tool that allows us to push changes to git, and have the tool auto-update from the repo without having to put git on systems.
It's written in PHP as this is the primary language in use at the office (specifically 5.3.3, although one of our devs is currently writing a technical specification for updating to 5.6), and it uses GitLab's api on our own internal gitlab host.
I've also spoofed a few details for privacy reasons, for example the config file is not called config.conf
, and the service is not called tool
.
<?php
//Until config can be loaded, assume _LOC is the directory of this script
$_LOC = realpath(dirname(__FILE__)).'/';
//Look for config file
echo "Searching for ".$_LOC."config/config.confn";
if (!file_exists($_LOC.'config/config.conf'))
echo "Searching for ".$_LOC."config/config.template.confn";
if (!file_exists($_LOC.'config/config.template.conf'))
exit('Config file does not exist and template was not found!');
//Create config from template
echo "Template exists, creating config filen";
copy($_LOC.'config/config.template.conf', $_LOC.'config/config.conf');
//Imports
require($_LOC.'lib/functions.php');
require($_LOC.'config/config.conf');
require('/etc/casper/defaults.conf');
if ($_DEBUG) echo "Starting update checkn";
if ($_DEBUG) echo "Fetching commitsn";
//Fetch all commits for set branch, default sorted by newest first
$commitsjson = gitlab_fetch("projects/$_GIT_ID/repository/commits", array('ref' => $_GIT_BRANCH));
$commits = json_decode($commitsjson);
$lastcommit = $commits[0];
$lastcommit = $lastcommit->id;
if ($_DEBUG) echo "Latest commit is ".$lastcommit."n";
if ($lastcommit !== $_UPDATE_SHA)
if ($_DEBUG) echo "But current update is ".$_UPDATE_SHA."nUpdating...";
//Fetch recursive tree of all files and directories
$filejson = gitlab_fetch("projects/$_GIT_ID/repository/tree", array('recursive' => 'true', 'ref' => $_GIT_BRANCH));
$fileinfo = json_decode($filejson);
//Create backup directory
$bakdate = date('Ymd');
$bakloc = $_LOC.'bak'.$bakdate.'/';
mkdir($bakloc);
$files = array();
$dirs = array();
//Format each file to url to fetch file contents and filter directories to separate array
foreach($fileinfo as $file)
if ($file->type == "blob")
$files[$file->path] = "projects/$_GIT_ID/repository/files/".$file->path;
else if ($file->type == "tree")
$dirs = $file->path;
//Create directories
foreach($dirs as $dir)
if ($_DEBUG) echo "Creating directory $dirn";
if (!file_exists($_LOC.$dir)) mkdir($_LOC.$dir);
else mkdir($bakloc.$dir);
//Fetch files
foreach($files as $path => $fileapi)
if ($_DEBUG) echo "Fetching $pathn";
//Fetch json
$fileraw = gitlab_fetch($fileapi, array('ref' => $_GIT_BRANCH));
$fileobj = json_decode($fileraw);
//If content is set, file was successfully pulled
if (isset($fileobj->content))
//content is provided in base64, need to decode
$filecontent = base64_decode($fileobj->content);
if ($_DEBUG) echo "Fetched ".strlen($fileobj->content)." bytes, decoded into ".strlen($filecontent)." bytesn";
//Backup file if it already exists
if (file_exists($_LOC.$path))
if ($_DEBUG) echo "Backing up $_LOC$path to $bakloc$pathn";
copy($_LOC.$path, $bakloc.$path);
if ($_DEBUG) echo "Overwriting $_LOC$pathn";
file_put_contents($_LOC.$path, $filecontent);
if ($_DEBUG) echo "Donen";
//If message is set, an error was returned
else if (isset($fileobj->message))
//Output the error
if ($_DEBUG) echo "Failed to download $path with response ".$fileobj->message."n";
//Update the commit hash
if ($_DEBUG) echo "Updating commit hashn";
file_put_contents($_LOC.'config/update-hash', $lastcommit);
if ($_DEBUG) echo "Restarting tool...n";
//Log restart in slack, and restart service
slack_pretty_log('Tool Updated', "Tool $_VERSION has updated! Restarting...", 'good');
$output = shell_exec('sudo /etc/init.d/tool restart 2>&1');
if ($_DEBUG) echo $output;
//End
else
if ($_DEBUG) echo "No new updatesn";
Functions such as slack_pretty_log
and gitlab_fetch
are defined externally and use the respective APIs, and any variables beginning with underscores (such as $_DEBUG
and $_GIT_BRANCH
) are defined in the config file.
I'm mainly interested in feedback on the flow of the logic itself, as well as naming conventions (which I admittedly didn't do a great job of adhering to) and comments.
This is a standalone script designed to run once per day on a cronjob, which is why it has a lot of logic outside of any functions or classes.
linux php5 git
At my office we have an internal monitoring tool we use on customer systems to monitor various vitals and notify us via Slack. Our Lead Dev and Chief Architect are very paranoid about Git, and outright refuse to put it on customer systems, however they still like the idea of using it for development.
So I created an autoupdater script for our monitoring tool that allows us to push changes to git, and have the tool auto-update from the repo without having to put git on systems.
It's written in PHP as this is the primary language in use at the office (specifically 5.3.3, although one of our devs is currently writing a technical specification for updating to 5.6), and it uses GitLab's api on our own internal gitlab host.
I've also spoofed a few details for privacy reasons, for example the config file is not called config.conf
, and the service is not called tool
.
<?php
//Until config can be loaded, assume _LOC is the directory of this script
$_LOC = realpath(dirname(__FILE__)).'/';
//Look for config file
echo "Searching for ".$_LOC."config/config.confn";
if (!file_exists($_LOC.'config/config.conf'))
echo "Searching for ".$_LOC."config/config.template.confn";
if (!file_exists($_LOC.'config/config.template.conf'))
exit('Config file does not exist and template was not found!');
//Create config from template
echo "Template exists, creating config filen";
copy($_LOC.'config/config.template.conf', $_LOC.'config/config.conf');
//Imports
require($_LOC.'lib/functions.php');
require($_LOC.'config/config.conf');
require('/etc/casper/defaults.conf');
if ($_DEBUG) echo "Starting update checkn";
if ($_DEBUG) echo "Fetching commitsn";
//Fetch all commits for set branch, default sorted by newest first
$commitsjson = gitlab_fetch("projects/$_GIT_ID/repository/commits", array('ref' => $_GIT_BRANCH));
$commits = json_decode($commitsjson);
$lastcommit = $commits[0];
$lastcommit = $lastcommit->id;
if ($_DEBUG) echo "Latest commit is ".$lastcommit."n";
if ($lastcommit !== $_UPDATE_SHA)
if ($_DEBUG) echo "But current update is ".$_UPDATE_SHA."nUpdating...";
//Fetch recursive tree of all files and directories
$filejson = gitlab_fetch("projects/$_GIT_ID/repository/tree", array('recursive' => 'true', 'ref' => $_GIT_BRANCH));
$fileinfo = json_decode($filejson);
//Create backup directory
$bakdate = date('Ymd');
$bakloc = $_LOC.'bak'.$bakdate.'/';
mkdir($bakloc);
$files = array();
$dirs = array();
//Format each file to url to fetch file contents and filter directories to separate array
foreach($fileinfo as $file)
if ($file->type == "blob")
$files[$file->path] = "projects/$_GIT_ID/repository/files/".$file->path;
else if ($file->type == "tree")
$dirs = $file->path;
//Create directories
foreach($dirs as $dir)
if ($_DEBUG) echo "Creating directory $dirn";
if (!file_exists($_LOC.$dir)) mkdir($_LOC.$dir);
else mkdir($bakloc.$dir);
//Fetch files
foreach($files as $path => $fileapi)
if ($_DEBUG) echo "Fetching $pathn";
//Fetch json
$fileraw = gitlab_fetch($fileapi, array('ref' => $_GIT_BRANCH));
$fileobj = json_decode($fileraw);
//If content is set, file was successfully pulled
if (isset($fileobj->content))
//content is provided in base64, need to decode
$filecontent = base64_decode($fileobj->content);
if ($_DEBUG) echo "Fetched ".strlen($fileobj->content)." bytes, decoded into ".strlen($filecontent)." bytesn";
//Backup file if it already exists
if (file_exists($_LOC.$path))
if ($_DEBUG) echo "Backing up $_LOC$path to $bakloc$pathn";
copy($_LOC.$path, $bakloc.$path);
if ($_DEBUG) echo "Overwriting $_LOC$pathn";
file_put_contents($_LOC.$path, $filecontent);
if ($_DEBUG) echo "Donen";
//If message is set, an error was returned
else if (isset($fileobj->message))
//Output the error
if ($_DEBUG) echo "Failed to download $path with response ".$fileobj->message."n";
//Update the commit hash
if ($_DEBUG) echo "Updating commit hashn";
file_put_contents($_LOC.'config/update-hash', $lastcommit);
if ($_DEBUG) echo "Restarting tool...n";
//Log restart in slack, and restart service
slack_pretty_log('Tool Updated', "Tool $_VERSION has updated! Restarting...", 'good');
$output = shell_exec('sudo /etc/init.d/tool restart 2>&1');
if ($_DEBUG) echo $output;
//End
else
if ($_DEBUG) echo "No new updatesn";
Functions such as slack_pretty_log
and gitlab_fetch
are defined externally and use the respective APIs, and any variables beginning with underscores (such as $_DEBUG
and $_GIT_BRANCH
) are defined in the config file.
I'm mainly interested in feedback on the flow of the logic itself, as well as naming conventions (which I admittedly didn't do a great job of adhering to) and comments.
This is a standalone script designed to run once per day on a cronjob, which is why it has a lot of logic outside of any functions or classes.
linux php5 git
edited Feb 7 at 17:26
200_success
123k14143401
123k14143401
asked Feb 7 at 16:15
Skidsdev
13613
13613
add a comment |Â
add a comment |Â
1 Answer
1
active
oldest
votes
up vote
1
down vote
Why have you repeated if ($_DEBUG) echo
a zillion times? That is begging to be embedded in a debug()
function.
Every time you have a comment with a chunk of logic underneath it, that should be a method (named what the comment says).
I agree with your comment regarding the debug echo repetition, and I've added a debug function for that now, however given the nature of the script, and the nature of function calls in PHP, it seems pointless and even counter productive to needlessly split the entire script up into functions that will only be run once
â Skidsdev
Feb 8 at 10:17
What, pray tell, is it about functions in PHP that makes introducing them a bad idea? The introduction is for readability, not performance.
â Bryan Boettcher
Feb 8 at 17:08
My issue, aside from the performance issues, is that it leads to a code flow like this, which in my opinion worsens readability, rather than improves it
â Skidsdev
Feb 8 at 17:33
Ah, yes, the performance issues from function overhead on a once-a-day script :) You're also stating, with a straight face, that a nested method call is LESS readable than 20 lines of code nested inside the same if statement?
â Bryan Boettcher
Feb 8 at 17:46
Yes I am, because if you just have a series of function calls within an if statement, you essentially have magic black boxes as far as readability is concerned, and you have to scroll down or open a different file to look at the function declarations, which breaks the flow completely
â Skidsdev
Feb 8 at 21:12
add a comment |Â
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
Why have you repeated if ($_DEBUG) echo
a zillion times? That is begging to be embedded in a debug()
function.
Every time you have a comment with a chunk of logic underneath it, that should be a method (named what the comment says).
I agree with your comment regarding the debug echo repetition, and I've added a debug function for that now, however given the nature of the script, and the nature of function calls in PHP, it seems pointless and even counter productive to needlessly split the entire script up into functions that will only be run once
â Skidsdev
Feb 8 at 10:17
What, pray tell, is it about functions in PHP that makes introducing them a bad idea? The introduction is for readability, not performance.
â Bryan Boettcher
Feb 8 at 17:08
My issue, aside from the performance issues, is that it leads to a code flow like this, which in my opinion worsens readability, rather than improves it
â Skidsdev
Feb 8 at 17:33
Ah, yes, the performance issues from function overhead on a once-a-day script :) You're also stating, with a straight face, that a nested method call is LESS readable than 20 lines of code nested inside the same if statement?
â Bryan Boettcher
Feb 8 at 17:46
Yes I am, because if you just have a series of function calls within an if statement, you essentially have magic black boxes as far as readability is concerned, and you have to scroll down or open a different file to look at the function declarations, which breaks the flow completely
â Skidsdev
Feb 8 at 21:12
add a comment |Â
up vote
1
down vote
Why have you repeated if ($_DEBUG) echo
a zillion times? That is begging to be embedded in a debug()
function.
Every time you have a comment with a chunk of logic underneath it, that should be a method (named what the comment says).
I agree with your comment regarding the debug echo repetition, and I've added a debug function for that now, however given the nature of the script, and the nature of function calls in PHP, it seems pointless and even counter productive to needlessly split the entire script up into functions that will only be run once
â Skidsdev
Feb 8 at 10:17
What, pray tell, is it about functions in PHP that makes introducing them a bad idea? The introduction is for readability, not performance.
â Bryan Boettcher
Feb 8 at 17:08
My issue, aside from the performance issues, is that it leads to a code flow like this, which in my opinion worsens readability, rather than improves it
â Skidsdev
Feb 8 at 17:33
Ah, yes, the performance issues from function overhead on a once-a-day script :) You're also stating, with a straight face, that a nested method call is LESS readable than 20 lines of code nested inside the same if statement?
â Bryan Boettcher
Feb 8 at 17:46
Yes I am, because if you just have a series of function calls within an if statement, you essentially have magic black boxes as far as readability is concerned, and you have to scroll down or open a different file to look at the function declarations, which breaks the flow completely
â Skidsdev
Feb 8 at 21:12
add a comment |Â
up vote
1
down vote
up vote
1
down vote
Why have you repeated if ($_DEBUG) echo
a zillion times? That is begging to be embedded in a debug()
function.
Every time you have a comment with a chunk of logic underneath it, that should be a method (named what the comment says).
Why have you repeated if ($_DEBUG) echo
a zillion times? That is begging to be embedded in a debug()
function.
Every time you have a comment with a chunk of logic underneath it, that should be a method (named what the comment says).
answered Feb 7 at 17:45
Bryan Boettcher
1234
1234
I agree with your comment regarding the debug echo repetition, and I've added a debug function for that now, however given the nature of the script, and the nature of function calls in PHP, it seems pointless and even counter productive to needlessly split the entire script up into functions that will only be run once
â Skidsdev
Feb 8 at 10:17
What, pray tell, is it about functions in PHP that makes introducing them a bad idea? The introduction is for readability, not performance.
â Bryan Boettcher
Feb 8 at 17:08
My issue, aside from the performance issues, is that it leads to a code flow like this, which in my opinion worsens readability, rather than improves it
â Skidsdev
Feb 8 at 17:33
Ah, yes, the performance issues from function overhead on a once-a-day script :) You're also stating, with a straight face, that a nested method call is LESS readable than 20 lines of code nested inside the same if statement?
â Bryan Boettcher
Feb 8 at 17:46
Yes I am, because if you just have a series of function calls within an if statement, you essentially have magic black boxes as far as readability is concerned, and you have to scroll down or open a different file to look at the function declarations, which breaks the flow completely
â Skidsdev
Feb 8 at 21:12
add a comment |Â
I agree with your comment regarding the debug echo repetition, and I've added a debug function for that now, however given the nature of the script, and the nature of function calls in PHP, it seems pointless and even counter productive to needlessly split the entire script up into functions that will only be run once
â Skidsdev
Feb 8 at 10:17
What, pray tell, is it about functions in PHP that makes introducing them a bad idea? The introduction is for readability, not performance.
â Bryan Boettcher
Feb 8 at 17:08
My issue, aside from the performance issues, is that it leads to a code flow like this, which in my opinion worsens readability, rather than improves it
â Skidsdev
Feb 8 at 17:33
Ah, yes, the performance issues from function overhead on a once-a-day script :) You're also stating, with a straight face, that a nested method call is LESS readable than 20 lines of code nested inside the same if statement?
â Bryan Boettcher
Feb 8 at 17:46
Yes I am, because if you just have a series of function calls within an if statement, you essentially have magic black boxes as far as readability is concerned, and you have to scroll down or open a different file to look at the function declarations, which breaks the flow completely
â Skidsdev
Feb 8 at 21:12
I agree with your comment regarding the debug echo repetition, and I've added a debug function for that now, however given the nature of the script, and the nature of function calls in PHP, it seems pointless and even counter productive to needlessly split the entire script up into functions that will only be run once
â Skidsdev
Feb 8 at 10:17
I agree with your comment regarding the debug echo repetition, and I've added a debug function for that now, however given the nature of the script, and the nature of function calls in PHP, it seems pointless and even counter productive to needlessly split the entire script up into functions that will only be run once
â Skidsdev
Feb 8 at 10:17
What, pray tell, is it about functions in PHP that makes introducing them a bad idea? The introduction is for readability, not performance.
â Bryan Boettcher
Feb 8 at 17:08
What, pray tell, is it about functions in PHP that makes introducing them a bad idea? The introduction is for readability, not performance.
â Bryan Boettcher
Feb 8 at 17:08
My issue, aside from the performance issues, is that it leads to a code flow like this, which in my opinion worsens readability, rather than improves it
â Skidsdev
Feb 8 at 17:33
My issue, aside from the performance issues, is that it leads to a code flow like this, which in my opinion worsens readability, rather than improves it
â Skidsdev
Feb 8 at 17:33
Ah, yes, the performance issues from function overhead on a once-a-day script :) You're also stating, with a straight face, that a nested method call is LESS readable than 20 lines of code nested inside the same if statement?
â Bryan Boettcher
Feb 8 at 17:46
Ah, yes, the performance issues from function overhead on a once-a-day script :) You're also stating, with a straight face, that a nested method call is LESS readable than 20 lines of code nested inside the same if statement?
â Bryan Boettcher
Feb 8 at 17:46
Yes I am, because if you just have a series of function calls within an if statement, you essentially have magic black boxes as far as readability is concerned, and you have to scroll down or open a different file to look at the function declarations, which breaks the flow completely
â Skidsdev
Feb 8 at 21:12
Yes I am, because if you just have a series of function calls within an if statement, you essentially have magic black boxes as far as readability is concerned, and you have to scroll down or open a different file to look at the function declarations, which breaks the flow completely
â Skidsdev
Feb 8 at 21:12
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f187020%2fgit-autoupdater%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password