src/js/pm_service_worker.js   A
last analyzed

Complexity

Total Complexity 10
Complexity/F 3.33

Size

Lines of Code 1
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
c 0
b 0
f 0
dl 0
loc 1
rs 10
wmc 10
mnd 7
bc 7
fnc 3
bpm 2.3333
cpm 3.3333
noi 8
1
importScripts('https://www.gstatic.com/firebasejs/6.6.1/firebase-app.js'),importScripts('https://www.gstatic.com/firebasejs/6.6.1/firebase-messaging.js'),importScripts('https://www.pushmix.co.uk/js/analytics-helper.js'),firebase.initializeApp({apiKey:'AIzaSyDvNBVsjhdUZPr1BD51tHtUCx-CidaTqKY',authDomain:'pushmix-216113.firebaseapp.com',projectId:'pushmix-216113',messagingSenderId:'542277997339'});const messaging=firebase.messaging();messaging.setBackgroundMessageHandler(function(a){var b=a.data.title,c={body:a.data.body,icon:a.data.icon,badge:a.data.badge,tag:'push-notification-tag'};return a.data.hasOwnProperty('image')&&(c.image=a.data.image),a.data.hasOwnProperty('urls')&&(c.data=JSON.parse(a.data.urls)),c.data.hasOwnProperty('gaTrackingId')?sendAnalyticsEvent('notification-view','web notification',c.data.gaTrackingId):c.data.gaTrackingId=null,a.data.hasOwnProperty('actions')&&'actions'in Notification.prototype&&(c.actions=JSON.parse(a.data.actions)),self.registration.showNotification(b,c)}),self.addEventListener('notificationclick',function(a){var b=a.notification.data.default_url,c='notification-click';if(a.action)switch(a.action){case'action-one':b=new URL(a.notification.data.action_url_one,self.location.origin).href,c=a.notification.actions[0].title;break;case'action-two':b=a.notification.data.action_url_two,c=a.notification.actions[1].title;}if(a.notification.close(),!1!==b){var d=clients.matchAll({type:'window',includeUncontrolled:!0}).then(function(f){for(var h,g=0;g<f.length;g++)if(h=f[g],h.url===b&&'focus'in h)return h.focus();if(clients.openWindow)return clients.openWindow(b)}),e=Promise.all([sendAnalyticsEvent(c,'web notification',a.notification.data.gaTrackingId),d]);a.waitUntil(e)}});
0 ignored issues
show
Bug introduced by
The variable Notification seems to be never declared. If this is a global, consider adding a /** global: Notification */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable URL seems to be never declared. If this is a global, consider adding a /** global: URL */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Complexity Best Practice introduced by
There is no return statement if clients.openWindow is false. Are you sure this is correct? If so, consider adding return; explicitly.

This check looks for functions where a return statement is found in some execution paths, but not in all.

Consider this little piece of code

function isBig(a) {
    if (a > 5000) {
        return "yes";
    }
}

console.log(isBig(5001)); //returns yes
console.log(isBig(42)); //returns undefined

The function isBig will only return a specific value when its parameter is bigger than 5000. In any other case, it will implicitly return undefined.

This behaviour may not be what you had intended. In any case, you can add a return undefined to the other execution path to make the return value explicit.

Loading history...
Bug introduced by
The variable clients seems to be never declared. If this is a global, consider adding a /** global: clients */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
Bug introduced by
The variable self seems to be never declared. If this is a global, consider adding a /** global: self */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Bug introduced by
The variable firebase seems to be never declared. If this is a global, consider adding a /** global: firebase */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...