1414 * https://github.com/adriangibbons/phpFITFileAnalysis
1515 * http://www.thisisant.com/resources/fit
1616 */
17-
18- define ('DEFINITION_MESSAGE ' , 1 );
19- define ('DATA_MESSAGE ' , 0 );
17+
18+ if (! defined ( ' DEFINITION_MESSAGE ' )) define ('DEFINITION_MESSAGE ' , 1 );
19+ if (! defined ( ' DATA_MESSAGE ' )) define ('DATA_MESSAGE ' , 0 );
2020
2121class phpFITFileAnalysis
2222{
@@ -608,10 +608,10 @@ class phpFITFileAnalysis
608608 public function __construct ($ file_path , $ options = null )
609609 {
610610 if (empty ($ file_path )) {
611- throw new Exception ('phpFITFileAnalysis->__construct(): file_path is empty! ' );
611+ throw new \ Exception ('phpFITFileAnalysis->__construct(): file_path is empty! ' );
612612 }
613613 if (!file_exists ($ file_path )) {
614- throw new Exception ('phpFITFileAnalysis->__construct(): file \'' .$ file_path .'\' does not exist! ' );
614+ throw new \ Exception ('phpFITFileAnalysis->__construct(): file \'' .$ file_path .'\' does not exist! ' );
615615 }
616616 $ this ->php_trader_ext_loaded = extension_loaded ('trader ' );
617617
@@ -642,7 +642,7 @@ private function readHeader()
642642 $ this ->file_pointer ++;
643643
644644 if ($ header_size != 12 && $ header_size != 14 ) {
645- throw new Exception ('phpFITFileAnalysis->readHeader(): not a valid header size! ' );
645+ throw new \ Exception ('phpFITFileAnalysis->readHeader(): not a valid header size! ' );
646646 }
647647
648648 $ header_fields = 'C1protocol_version/ ' .
@@ -660,11 +660,11 @@ private function readHeader()
660660 $ file_extension = sprintf ('%c%c%c%c ' , $ this ->file_header ['data_type1 ' ], $ this ->file_header ['data_type2 ' ], $ this ->file_header ['data_type3 ' ], $ this ->file_header ['data_type4 ' ]);
661661
662662 if ($ file_extension != '.FIT ' || $ this ->file_header ['data_size ' ] <= 0 ) {
663- throw new Exception ('phpFITFileAnalysis->readHeader(): not a valid FIT file! ' );
663+ throw new \ Exception ('phpFITFileAnalysis->readHeader(): not a valid FIT file! ' );
664664 }
665665
666666 if (strlen ($ this ->file_contents ) - $ header_size - 2 !== $ this ->file_header ['data_size ' ]) {
667- throw new Exception ('phpFITFileAnalysis->readHeader(): file_header[ \'data_size \'] does not seem correct! ' );
667+ throw new \ Exception ('phpFITFileAnalysis->readHeader(): file_header[ \'data_size \'] does not seem correct! ' );
668668 }
669669 }
670670
@@ -686,7 +686,7 @@ private function readDataRecords()
686686 * Table 4-1. Normal Header Bit Field Description
687687 */
688688 if (($ record_header_byte >> 7 ) & 1 ) { // Check that it's a normal header
689- throw new Exception ('phpFITFileAnalysis->readDataRecords(): this class can only handle normal headers! ' );
689+ throw new \ Exception ('phpFITFileAnalysis->readDataRecords(): this class can only handle normal headers! ' );
690690 }
691691 $ message_type = ($ record_header_byte >> 6 ) & 1 ; // 1: DEFINITION_MESSAGE; 0: DATA_MESSAGE
692692 $ local_mesg_type = $ record_header_byte & 15 ; // bindec('1111') == 15
@@ -861,7 +861,7 @@ private function fixData($options)
861861
862862 }); // Make all lower-case.
863863 if (count (array_intersect (['all ' , 'cadence ' , 'distance ' , 'heart_rate ' , 'lat_lon ' , 'speed ' , 'power ' ], $ options ['fixData ' ])) === 0 ) {
864- throw new Exception ('phpFITFileAnalysis->fixData(): option not valid! ' );
864+ throw new \ Exception ('phpFITFileAnalysis->fixData(): option not valid! ' );
865865 }
866866
867867 $ bCadence = $ bDistance = $ bHeartRate = $ bLatitudeLongitude = $ bSpeed = $ bPower = false ;
@@ -1097,10 +1097,10 @@ private function setUnits($options)
10971097 if ($ pace === 'true ' || $ pace === 'false ' ) {
10981098 $ bPace = $ pace ;
10991099 } else {
1100- throw new Exception ('phpFITFileAnalysis->setUnits(): pace option not valid! ' );
1100+ throw new \ Exception ('phpFITFileAnalysis->setUnits(): pace option not valid! ' );
11011101 }
11021102 } else {
1103- throw new Exception ('phpFITFileAnalysis->setUnits(): pace option not valid! ' );
1103+ throw new \ Exception ('phpFITFileAnalysis->setUnits(): pace option not valid! ' );
11041104 }
11051105 }
11061106
@@ -1219,7 +1219,7 @@ private function setUnits($options)
12191219 }
12201220 break ;
12211221 default :
1222- throw new Exception ('phpFITFileAnalysis->setUnits(): units option not valid! ' );
1222+ throw new \ Exception ('phpFITFileAnalysis->setUnits(): units option not valid! ' );
12231223 break ;
12241224 }
12251225 }
@@ -1235,7 +1235,7 @@ public function hrZonesMax($hr_maximum, $percentages_array = [0.60, 0.75, 0.85,
12351235 }, $ hr_maximum )) {
12361236 return $ percentages_array ;
12371237 } else {
1238- throw new Exception ('phpFITFileAnalysis->hrZonesMax(): cannot calculate zones, please check inputs! ' );
1238+ throw new \ Exception ('phpFITFileAnalysis->hrZonesMax(): cannot calculate zones, please check inputs! ' );
12391239 }
12401240 }
12411241
@@ -1250,7 +1250,7 @@ public function hrZonesReserve($hr_resting, $hr_maximum, $percentages_array = [0
12501250 }, [$ hr_resting , $ hr_maximum - $ hr_resting ])) {
12511251 return $ percentages_array ;
12521252 } else {
1253- throw new Exception ('phpFITFileAnalysis->hrZonesReserve(): cannot calculate zones, please check inputs! ' );
1253+ throw new \ Exception ('phpFITFileAnalysis->hrZonesReserve(): cannot calculate zones, please check inputs! ' );
12541254 }
12551255 }
12561256
@@ -1265,7 +1265,7 @@ public function powerZones($functional_threshold_power, $percentages_array = [0.
12651265 }, $ functional_threshold_power )) {
12661266 return $ percentages_array ;
12671267 } else {
1268- throw new Exception ('phpFITFileAnalysis->powerZones(): cannot calculate zones, please check inputs! ' );
1268+ throw new \ Exception ('phpFITFileAnalysis->powerZones(): cannot calculate zones, please check inputs! ' );
12691269 }
12701270 }
12711271
@@ -1275,18 +1275,18 @@ public function powerZones($functional_threshold_power, $percentages_array = [0.
12751275 public function partitionData ($ record_field = '' , $ thresholds = null , $ percentages = true , $ labels_for_keys = true )
12761276 {
12771277 if (!isset ($ this ->data_mesgs ['record ' ][$ record_field ])) {
1278- throw new Exception ('phpFITFileAnalysis->partitionData(): ' .$ record_field .' data not present in FIT file! ' );
1278+ throw new \ Exception ('phpFITFileAnalysis->partitionData(): ' .$ record_field .' data not present in FIT file! ' );
12791279 }
12801280 if (!is_array ($ thresholds )) {
1281- throw new Exception ('phpFITFileAnalysis->partitionData(): thresholds must be an array e.g. [10,20,30,40,50]! ' );
1281+ throw new \ Exception ('phpFITFileAnalysis->partitionData(): thresholds must be an array e.g. [10,20,30,40,50]! ' );
12821282 }
12831283
12841284 foreach ($ thresholds as $ threshold ) {
12851285 if (!is_numeric ($ threshold ) || $ threshold < 0 ) {
1286- throw new Exception ('phpFITFileAnalysis->partitionData(): ' .$ threshold .' not valid in thresholds! ' );
1286+ throw new \ Exception ('phpFITFileAnalysis->partitionData(): ' .$ threshold .' not valid in thresholds! ' );
12871287 }
12881288 if (isset ($ last_threshold ) && $ last_threshold >= $ threshold ) {
1289- throw new Exception ('phpFITFileAnalysis->partitionData(): error near ..., ' .$ last_threshold .', ' .$ threshold .', ... - each element in thresholds array must be greater than previous element! ' );
1289+ throw new \ Exception ('phpFITFileAnalysis->partitionData(): error near ..., ' .$ last_threshold .', ' .$ threshold .', ... - each element in thresholds array must be greater than previous element! ' );
12901290 }
12911291 $ last_threshold = $ threshold ;
12921292 }
@@ -1332,10 +1332,10 @@ public function partitionData($record_field = '', $thresholds = null, $percentag
13321332 public function histogram ($ bucket_width = 25 , $ record_field = '' )
13331333 {
13341334 if (!isset ($ this ->data_mesgs ['record ' ][$ record_field ])) {
1335- throw new Exception ('phpFITFileAnalysis->histogram(): ' .$ record_field .' data not present in FIT file! ' );
1335+ throw new \ Exception ('phpFITFileAnalysis->histogram(): ' .$ record_field .' data not present in FIT file! ' );
13361336 }
13371337 if (!is_numeric ($ bucket_width ) || $ bucket_width <= 0 ) {
1338- throw new Exception ('phpFITFileAnalysis->histogram(): bucket width is not valid! ' );
1338+ throw new \ Exception ('phpFITFileAnalysis->histogram(): bucket width is not valid! ' );
13391339 }
13401340
13411341 foreach ($ this ->data_mesgs ['record ' ][$ record_field ] as $ value ) {
@@ -1425,7 +1425,7 @@ public function hrMetrics($hr_resting, $hr_maximum, $hr_FT, $gender)
14251425 public function powerMetrics ($ functional_threshold_power )
14261426 {
14271427 if (!isset ($ this ->data_mesgs ['record ' ]['power ' ])) {
1428- throw new Exception ('phpFITFileAnalysis->powerMetrics(): power data not present in FIT file! ' );
1428+ throw new \ Exception ('phpFITFileAnalysis->powerMetrics(): power data not present in FIT file! ' );
14291429 }
14301430
14311431 $ power_metrics ['Average Power ' ] = array_sum ($ this ->data_mesgs ['record ' ]['power ' ]) / count ($ this ->data_mesgs ['record ' ]['power ' ]);
@@ -1462,17 +1462,17 @@ public function powerMetrics($functional_threshold_power)
14621462 public function criticalPower ($ time_periods )
14631463 {
14641464 if (!isset ($ this ->data_mesgs ['record ' ]['power ' ])) {
1465- throw new Exception ('phpFITFileAnalysis->criticalPower(): power data not present in FIT file! ' );
1465+ throw new \ Exception ('phpFITFileAnalysis->criticalPower(): power data not present in FIT file! ' );
14661466 }
14671467
14681468 if (is_array ($ time_periods )) {
14691469 $ count = count ($ this ->data_mesgs ['record ' ]['power ' ]);
14701470 foreach ($ time_periods as $ time_period ) {
14711471 if (!is_numeric ($ time_period )) {
1472- throw new Exception ('phpFITFileAnalysis->criticalPower(): time periods must only contain numeric data! ' );
1472+ throw new \ Exception ('phpFITFileAnalysis->criticalPower(): time periods must only contain numeric data! ' );
14731473 }
14741474 if ($ time_period < 0 ) {
1475- throw new Exception ('phpFITFileAnalysis->criticalPower(): time periods cannot be negative! ' );
1475+ throw new \ Exception ('phpFITFileAnalysis->criticalPower(): time periods cannot be negative! ' );
14761476 }
14771477 if ($ time_period > $ count ) {
14781478 break ;
@@ -1497,7 +1497,7 @@ public function criticalPower($time_periods)
14971497
14981498 return $ criticalPower_values ;
14991499 } else {
1500- throw new Exception ('phpFITFileAnalysis->criticalPower(): time periods not valid! ' );
1500+ throw new \ Exception ('phpFITFileAnalysis->criticalPower(): time periods not valid! ' );
15011501 }
15021502 }
15031503
0 commit comments